diff options
author | Junio C Hamano <gitster@pobox.com> | 2019-07-25 14:27:07 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-07-25 14:27:07 -0700 |
commit | 933f294877bac77c6159d93220c5910954712025 (patch) | |
tree | a2a539cc1846562eeec599b128466600b1096f18 | |
parent | Merge branch 'nd/init-relative-template-fix' into maint (diff) | |
parent | worktree add: be tolerant of corrupt worktrees (diff) | |
download | tgif-933f294877bac77c6159d93220c5910954712025.tar.xz |
Merge branch 'nd/corrupt-worktrees' into maint
"git worktree add" used to fail when another worktree connected to
the same repository was corrupt, which has been corrected.
* nd/corrupt-worktrees:
worktree add: be tolerant of corrupt worktrees
-rwxr-xr-x | t/t2400-worktree-add.sh | 12 | ||||
-rw-r--r-- | worktree.c | 7 |
2 files changed, 17 insertions, 2 deletions
diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index 286bba35d8..d83a9f0fdc 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -570,4 +570,16 @@ test_expect_success '"add" an existing locked but missing worktree' ' git worktree add --force --force --detach gnoo ' +test_expect_success '"add" should not fail because of another bad worktree' ' + git init add-fail && + ( + cd add-fail && + test_commit first && + mkdir sub && + git worktree add sub/to-be-deleted && + rm -rf sub && + git worktree add second + ) +' + test_done diff --git a/worktree.c b/worktree.c index 4f66cd9ce1..5b4793caa3 100644 --- a/worktree.c +++ b/worktree.c @@ -228,9 +228,12 @@ struct worktree *find_worktree(struct worktree **list, free(to_free); return NULL; } - for (; *list; list++) - if (!fspathcmp(path, real_path((*list)->path))) + for (; *list; list++) { + const char *wt_path = real_path_if_valid((*list)->path); + + if (wt_path && !fspathcmp(path, wt_path)) break; + } free(path); free(to_free); return *list; |