worktree remove: allow it when $GIT_WORK_TREE is already gone
"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 <kaartic.sivaraam@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
cc73385cf6
commit
ee6763af0a
@ -267,7 +267,8 @@ static void strbuf_addf_gently(struct strbuf *buf, const char *fmt, ...)
|
||||
va_end(params);
|
||||
}
|
||||
|
||||
int validate_worktree(const struct worktree *wt, struct strbuf *errmsg)
|
||||
int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,
|
||||
unsigned flags)
|
||||
{
|
||||
struct strbuf wt_path = STRBUF_INIT;
|
||||
char *path = NULL;
|
||||
@ -303,6 +304,12 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (flags & WT_VALIDATE_WORKTREE_MISSING_OK &&
|
||||
!file_exists(wt->path)) {
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!file_exists(wt_path.buf)) {
|
||||
strbuf_addf_gently(errmsg, _("'%s' does not exist"), wt_path.buf);
|
||||
goto done;
|
||||
|
Reference in New Issue
Block a user