Skip to content

Commit 04a3dfb

Browse files
pcloudsgitster
authored andcommitted
worktree.c: check whether branch is bisected in another worktree
Similar to the rebase case, we want to detect if "HEAD" in some worktree is being bisected because 1) we do not want to checkout this branch in another worktree, after bisect is done it will want to go back to this branch 2) we do not want to delete the branch is either or git bisect will fail to return to the (long gone) branch Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f5d067a commit 04a3dfb

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

t/t2025-worktree-add.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,17 @@ test_expect_success 'check out from current worktree branch ok' '
263263
)
264264
'
265265

266+
test_expect_success 'checkout a branch under bisect' '
267+
git worktree add under-bisect &&
268+
(
269+
cd under-bisect &&
270+
git bisect start &&
271+
git bisect bad &&
272+
git bisect good HEAD~2 &&
273+
git worktree list | grep "under-bisect.*detached HEAD" &&
274+
test_must_fail git worktree add new-bisect under-bisect &&
275+
! test -d new-bisect
276+
)
277+
'
278+
266279
test_done

worktree.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ static int is_worktree_being_rebased(const struct worktree *wt,
234234
return found_rebase;
235235
}
236236

237+
static int is_worktree_being_bisected(const struct worktree *wt,
238+
const char *target)
239+
{
240+
struct wt_status_state state;
241+
int found_rebase;
242+
243+
memset(&state, 0, sizeof(state));
244+
found_rebase = wt_status_check_bisect(wt, &state) &&
245+
state.branch &&
246+
starts_with(target, "refs/heads/") &&
247+
!strcmp(state.branch, target + strlen("refs/heads/"));
248+
free(state.branch);
249+
return found_rebase;
250+
}
251+
237252
/*
238253
* note: this function should be able to detect shared symref even if
239254
* 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,
261276
existing = wt;
262277
break;
263278
}
279+
if (is_worktree_being_bisected(wt, target)) {
280+
existing = wt;
281+
break;
282+
}
264283
}
265284

266285
strbuf_reset(&path);

0 commit comments

Comments
 (0)