* 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
| 1323 | * know better. |
| 1324 | */ |
| 1325 | static 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 | |
| 1364 | static int delete_git_work_tree(struct worktree *wt) |
| 1365 | { |
no test coverage detected