Skip to content

Commit 933f294

Browse files
committed
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
2 parents 35d7715 + 105df73 commit 933f294

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

t/t2400-worktree-add.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,4 +570,16 @@ test_expect_success '"add" an existing locked but missing worktree' '
570570
git worktree add --force --force --detach gnoo
571571
'
572572

573+
test_expect_success '"add" should not fail because of another bad worktree' '
574+
git init add-fail &&
575+
(
576+
cd add-fail &&
577+
test_commit first &&
578+
mkdir sub &&
579+
git worktree add sub/to-be-deleted &&
580+
rm -rf sub &&
581+
git worktree add second
582+
)
583+
'
584+
573585
test_done

worktree.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,12 @@ struct worktree *find_worktree(struct worktree **list,
228228
free(to_free);
229229
return NULL;
230230
}
231-
for (; *list; list++)
232-
if (!fspathcmp(path, real_path((*list)->path)))
231+
for (; *list; list++) {
232+
const char *wt_path = real_path_if_valid((*list)->path);
233+
234+
if (wt_path && !fspathcmp(path, wt_path))
233235
break;
236+
}
234237
free(path);
235238
free(to_free);
236239
return *list;

0 commit comments

Comments
 (0)