// https://github.com/git/git/blob/8d96f09e9245ddf80c1981476fcbac8c4bb4125f/builtin/worktree.c#L1378-L1431
staticintremove_worktree(int ac, constchar**av, constchar*prefix,
struct repository *repo UNUSED)
{
int force =0;
struct option options[] = {
OPT__FORCE(&force,
N_("force removal even if worktree is dirty or locked"),
PARSE_OPT_NOCOMPLETE),
OPT_END()
};
struct worktree **worktrees, *wt;
struct strbuf errmsg = STRBUF_INIT;
constchar*reason = NULL;
int ret =0;
ac =parse_options(ac, av, prefix, options, git_worktree_remove_usage, 0);
if (ac !=1)
usage_with_options(git_worktree_remove_usage, options);
// worktree全体から対象のworktreeを取得
worktrees =get_worktrees();
wt =find_worktree(worktrees, prefix, av[0]);
if (!wt) // NULLが返った == 見つからなかった
die(_("'%s' is not a working tree"), av[0]);
if (is_main_worktree(wt))
die(_("'%s' is a main working tree"), av[0]);
if (force <2)
reason =worktree_lock_reason(wt);
if (reason) {
if (*reason)
die(_("cannot remove a locked working tree, lock reason: %s\nuse 'remove -f -f' to override or unlock first"),
reason);
die(_("cannot remove a locked working tree;\nuse 'remove -f -f' to override or unlock first"));
}
if (validate_worktree(wt, &errmsg, WT_VALIDATE_WORKTREE_MISSING_OK))
die(_("validation failed, cannot remove working tree: %s"),
errmsg.buf);
strbuf_release(&errmsg);
if (file_exists(wt->path)) {
if (!force)
check_clean_worktree(wt, av[0]);
// worktreeのworking directoryを削除
ret |=delete_git_work_tree(wt);
}
/*
* continue on even if ret is non-zero, there's no going back
* from here.
*/// .git/worktrees/<id>を削除
ret |=delete_git_dir(wt->id);
delete_worktrees_dir_if_empty();
free_worktrees(worktrees);
return ret;
}
This site uses Google Analytics for access analysis.
Google Analytics uses cookies to collect traffic data, but this traffic data is collected anonymously and does not personally identify you.
Cookies can be disabled in your browser.