diff options
-rwxr-xr-x | t/t2025-worktree-add.sh | 13 | ||||
-rw-r--r-- | worktree.c | 19 |
2 files changed, 32 insertions, 0 deletions
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh index da54327f5d..8f53944cb2 100755 --- a/t/t2025-worktree-add.sh +++ b/t/t2025-worktree-add.sh @@ -263,4 +263,17 @@ test_expect_success 'check out from current worktree branch ok' ' ) ' +test_expect_success 'checkout a branch under bisect' ' + git worktree add under-bisect && + ( + cd under-bisect && + git bisect start && + git bisect bad && + git bisect good HEAD~2 && + git worktree list | grep "under-bisect.*detached HEAD" && + test_must_fail git worktree add new-bisect under-bisect && + ! test -d new-bisect + ) +' + test_done diff --git a/worktree.c b/worktree.c index 5043756663..aab4b9552e 100644 --- a/worktree.c +++ b/worktree.c @@ -234,6 +234,21 @@ static int is_worktree_being_rebased(const struct worktree *wt, return found_rebase; } +static int is_worktree_being_bisected(const struct worktree *wt, + const char *target) +{ + struct wt_status_state state; + int found_rebase; + + memset(&state, 0, sizeof(state)); + found_rebase = wt_status_check_bisect(wt, &state) && + state.branch && + starts_with(target, "refs/heads/") && + !strcmp(state.branch, target + strlen("refs/heads/")); + free(state.branch); + return found_rebase; +} + /* * note: this function should be able to detect shared symref even if * HEAD is temporarily detached (e.g. in the middle of rebase or @@ -261,6 +276,10 @@ const struct worktree *find_shared_symref(const char *symref, existing = wt; break; } + if (is_worktree_being_bisected(wt, target)) { + existing = wt; + break; + } } strbuf_reset(&path); |