| 1376 | } |
| 1377 | |
| 1378 | static int remove_worktree(int ac, const char **av, const char *prefix, |
| 1379 | struct repository *repo UNUSED) |
| 1380 | { |
| 1381 | int force = 0; |
| 1382 | struct option options[] = { |
| 1383 | OPT__FORCE(&force, |
| 1384 | N_("force removal even if worktree is dirty or locked"), |
| 1385 | PARSE_OPT_NOCOMPLETE), |
| 1386 | OPT_END() |
| 1387 | }; |
| 1388 | struct worktree **worktrees, *wt; |
| 1389 | struct strbuf errmsg = STRBUF_INIT; |
| 1390 | const char *reason = NULL; |
| 1391 | int ret = 0; |
| 1392 | |
| 1393 | ac = parse_options(ac, av, prefix, options, git_worktree_remove_usage, 0); |
| 1394 | if (ac != 1) |
| 1395 | usage_with_options(git_worktree_remove_usage, options); |
| 1396 | |
| 1397 | worktrees = get_worktrees(); |
| 1398 | wt = find_worktree(worktrees, prefix, av[0]); |
| 1399 | if (!wt) |
| 1400 | die(_("'%s' is not a working tree"), av[0]); |
| 1401 | if (is_main_worktree(wt)) |
| 1402 | die(_("'%s' is a main working tree"), av[0]); |
| 1403 | if (force < 2) |
| 1404 | reason = worktree_lock_reason(wt); |
| 1405 | if (reason) { |
| 1406 | if (*reason) |
| 1407 | die(_("cannot remove a locked working tree, lock reason: %s\nuse 'remove -f -f' to override or unlock first"), |
| 1408 | reason); |
| 1409 | die(_("cannot remove a locked working tree;\nuse 'remove -f -f' to override or unlock first")); |
| 1410 | } |
| 1411 | if (validate_worktree(wt, &errmsg, WT_VALIDATE_WORKTREE_MISSING_OK)) |
| 1412 | die(_("validation failed, cannot remove working tree: %s"), |
| 1413 | errmsg.buf); |
| 1414 | strbuf_release(&errmsg); |
| 1415 | |
| 1416 | if (file_exists(wt->path)) { |
| 1417 | if (!force) |
| 1418 | check_clean_worktree(wt, av[0]); |
| 1419 | |
| 1420 | ret |= delete_git_work_tree(wt); |
| 1421 | } |
| 1422 | /* |
| 1423 | * continue on even if ret is non-zero, there's no going back |
| 1424 | * from here. |
| 1425 | */ |
| 1426 | ret |= delete_git_dir(wt->id); |
| 1427 | delete_worktrees_dir_if_empty(); |
| 1428 | |
| 1429 | free_worktrees(worktrees); |
| 1430 | return ret; |
| 1431 | } |
| 1432 | |
| 1433 | static void report_repair(int iserr, const char *path, const char *msg, void *cb_data) |
| 1434 | { |
nothing calls this directly
no test coverage detected