bisect: fix "reset" when branch is checked out elsewhere
Since 1d0fa89 (checkout: add --ignore-other-wortrees, 2015-01-03) we have a safety valve in checkout/switch to prevent the same branch from being checked out simultaneously in multiple worktrees. If a branch is bisected in a worktree while also being checked out in another worktree; when the bisection is finished, checking out the branch back in the current worktree may fail. Let's teach bisect to use the "--ignore-other-worktrees" flag. Signed-off-by: Rubén Justo <rjusto@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Rubén Justo committed
Jan 22, 2023 at 02:38 UTC
7fb89047cc3957bf829233786c00edd5d87f0225
2 files changed
+25
-1
builtin/bisect.c
+2
-1
@@ -244,7 +244,8 @@ static int bisect_reset(const char *commit)
244
struct child_process cmd = CHILD_PROCESS_INIT;
245
246
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);
249
if (run_command(&cmd)) {
250
error(_("could not check out original"
251
" HEAD '%s'. Try 'git bisect"
t/t6030-bisect-porcelain.sh
+23
@@ -122,6 +122,29 @@ test_expect_success 'bisect start without -- takes unknown arg as pathspec' '
122
grep bar ".git/BISECT_NAMES"
123
'
124
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
+
148
test_expect_success 'bisect reset: back in the main branch' '
149
git bisect reset &&
150
echo "* main" > branch.expect &&