Skip to content

Commit 000bce0

Browse files
committed
Merge branch 'nd/corrupt-worktrees'
"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 ed7f8ac + 105df73 commit 000bce0

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
@@ -575,4 +575,16 @@ test_expect_success FUNNYNAMES 'sanitize generated worktree name' '
575575
test -d .git/worktrees/---weird-.-
576576
'
577577

578+
test_expect_success '"add" should not fail because of another bad worktree' '
579+
git init add-fail &&
580+
(
581+
cd add-fail &&
582+
test_commit first &&
583+
mkdir sub &&
584+
git worktree add sub/to-be-deleted &&
585+
rm -rf sub &&
586+
git worktree add second
587+
)
588+
'
589+
578590
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)