Skip to content

Commit c79786c

Browse files
committed
Merge branch 'rj/bisect-already-used-branch'
Allow "git bisect reset" to check out the original branch when the branch is already checked out in a different worktree linked to the same repository. * rj/bisect-already-used-branch: bisect: fix "reset" when branch is checked out elsewhere
2 parents 4a25b91 + 7fb8904 commit c79786c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

builtin/bisect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ static int bisect_reset(const char *commit)
245245
struct child_process cmd = CHILD_PROCESS_INIT;
246246

247247
cmd.git_cmd = 1;
248-
strvec_pushl(&cmd.args, "checkout", branch.buf, "--", NULL);
248+
strvec_pushl(&cmd.args, "checkout", "--ignore-other-worktrees",
249+
branch.buf, "--", NULL);
249250
if (run_command(&cmd)) {
250251
error(_("could not check out original"
251252
" HEAD '%s'. Try 'git bisect"

t/t6030-bisect-porcelain.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,29 @@ test_expect_success 'bisect start without -- takes unknown arg as pathspec' '
122122
grep bar ".git/BISECT_NAMES"
123123
'
124124

125+
test_expect_success 'bisect reset: back in a branch checked out also elsewhere' '
126+
echo "shared" > branch.expect &&
127+
test_bisect_reset() {
128+
git -C $1 bisect start &&
129+
git -C $1 bisect good $HASH1 &&
130+
git -C $1 bisect bad $HASH3 &&
131+
git -C $1 bisect reset &&
132+
git -C $1 branch --show-current > branch.output &&
133+
cmp branch.expect branch.output
134+
} &&
135+
test_when_finished "
136+
git worktree remove wt1 &&
137+
git worktree remove wt2 &&
138+
git branch -d shared
139+
" &&
140+
git worktree add wt1 -b shared &&
141+
git worktree add wt2 -f shared &&
142+
# we test in both worktrees to ensure that works
143+
# as expected with "first" and "next" worktrees
144+
test_bisect_reset wt1 &&
145+
test_bisect_reset wt2
146+
'
147+
125148
test_expect_success 'bisect reset: back in the main branch' '
126149
git bisect reset &&
127150
echo "* main" > branch.expect &&

0 commit comments

Comments
 (0)