From ee6763af0a3b97225803c6c908a29de40336cf38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 12 Feb 2018 16:49:40 +0700 Subject: worktree remove: allow it when $GIT_WORK_TREE is already gone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "git worktree remove" basically consists of two things - delete $GIT_WORK_TREE - delete $GIT_DIR (which is $SUPER_GIT_DIR/worktrees/something) If $GIT_WORK_TREE is already gone for some reason, we should be able to finish the job by deleting $GIT_DIR. Two notes: - $GIT_WORK_TREE _can_ be missing if the worktree is locked. In that case we must not delete $GIT_DIR because the real $GIT_WORK_TREE may be in a usb stick somewhere. This is already handled because we check for lock first. - validate_worktree() is still called because it may do more checks in future (and it already does something else, like checking main worktree, but that's irrelevant in this case) Noticed-by: Kaartic Sivaraam Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/worktree.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'builtin') diff --git a/builtin/worktree.c b/builtin/worktree.c index 990e47b315..f77ef994c4 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -674,7 +674,7 @@ static int move_worktree(int ac, const char **av, const char *prefix) reason); die(_("cannot move a locked working tree")); } - if (validate_worktree(wt, &errmsg)) + if (validate_worktree(wt, &errmsg, 0)) die(_("validation failed, cannot move working tree: %s"), errmsg.buf); strbuf_release(&errmsg); @@ -799,15 +799,17 @@ static int remove_worktree(int ac, const char **av, const char *prefix) reason); die(_("cannot remove a locked working tree")); } - if (validate_worktree(wt, &errmsg)) + if (validate_worktree(wt, &errmsg, WT_VALIDATE_WORKTREE_MISSING_OK)) die(_("validation failed, cannot remove working tree: %s"), errmsg.buf); strbuf_release(&errmsg); - if (!force) - check_clean_worktree(wt, av[0]); + if (file_exists(wt->path)) { + if (!force) + check_clean_worktree(wt, av[0]); - ret |= delete_git_work_tree(wt); + ret |= delete_git_work_tree(wt); + } /* * continue on even if ret is non-zero, there's no going back * from here. -- cgit v1.2.3