Skip to content

Commit cb1623c

Browse files
committed
Merge branch 'rj/bisect-already-used-branch' into seen
Allow "git bisect reset [name]" to check out the named branch (or the original one) even when the branch is already checked out in a different worktree linked to the same repository. Leaning negative. Why is it a good thing? cf. <[email protected]> * rj/bisect-already-used-branch: bisect: fix "reset" when branch is checked out elsewhere
2 parents 6b2ee4a + 7fb8904 commit cb1623c

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
@@ -244,7 +244,8 @@ static int bisect_reset(const char *commit)
244244
struct child_process cmd = CHILD_PROCESS_INIT;
245245

246246
cmd.git_cmd = 1;
247-
strvec_pushl(&cmd.args, "checkout", branch.buf, "--", NULL);
247+
strvec_pushl(&cmd.args, "checkout", "--ignore-other-worktrees",
248+
branch.buf, "--", NULL);
248249
if (run_command(&cmd)) {
249250
error(_("could not check out original"
250251
" 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)