MCPcopy Create free account
hub / github.com/git/git / check_clean_worktree

Function check_clean_worktree

builtin/worktree.c:1325–1362  ·  view source on GitHub ↗

* Note, "git status --porcelain" is used to determine if it's safe to * delete a whole worktree. "git status" does not ignore user * configuration, so if a normal "git status" shows "clean" for the * user, then it's ok to remove it. * * This assumption may be a bad one. We may want to ignore * (potentially bad) user settings and only delete a worktree when * it's absolutely safe to do so fr

Source from the content-addressed store, hash-verified

1323 * know better.
1324 */
1325static void check_clean_worktree(struct worktree *wt,
1326 const char *original_path)
1327{
1328 struct child_process cp;
1329 char buf[1];
1330 int ret;
1331
1332 /*
1333 * Until we sort this out, all submodules are "dirty" and
1334 * will abort this function.
1335 */
1336 validate_no_submodules(wt);
1337
1338 child_process_init(&cp);
1339 strvec_pushf(&cp.env, "%s=%s/.git",
1340 GIT_DIR_ENVIRONMENT, wt->path);
1341 strvec_pushf(&cp.env, "%s=%s",
1342 GIT_WORK_TREE_ENVIRONMENT, wt->path);
1343 strvec_pushl(&cp.args, "status",
1344 "--porcelain", "--ignore-submodules=none",
1345 NULL);
1346 cp.git_cmd = 1;
1347 cp.dir = wt->path;
1348 cp.out = -1;
1349 ret = start_command(&cp);
1350 if (ret)
1351 die_errno(_("failed to run 'git status' on '%s'"),
1352 original_path);
1353 ret = xread(cp.out, buf, sizeof(buf));
1354 if (ret)
1355 die(_("'%s' contains modified or untracked files, use --force to delete it"),
1356 original_path);
1357 close(cp.out);
1358 ret = finish_command(&cp);
1359 if (ret)
1360 die_errno(_("failed to run 'git status' on '%s', code %d"),
1361 original_path, ret);
1362}
1363
1364static int delete_git_work_tree(struct worktree *wt)
1365{

Callers 1

remove_worktreeFunction · 0.85

Calls 9

validate_no_submodulesFunction · 0.85
child_process_initFunction · 0.85
strvec_pushfFunction · 0.85
strvec_pushlFunction · 0.85
start_commandFunction · 0.85
die_errnoFunction · 0.85
xreadFunction · 0.85
finish_commandFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected