]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bisect: fix "reset" when branch is checked out elsewhere
authorRubén Justo <rjusto@gmail.com>
Sun, 22 Jan 2023 01:38:10 +0000 (02:38 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Jan 2023 17:23:11 +0000 (09:23 -0800)
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>
builtin/bisect.c
t/t6030-bisect-porcelain.sh

index 73017402671d30ce7f868a9691f9bb6f520695e1..e405fff9e9cf40c91e478fb8749fc26c81e30f8d 100644 (file)
@@ -244,7 +244,8 @@ static int bisect_reset(const char *commit)
                struct child_process cmd = CHILD_PROCESS_INIT;
 
                cmd.git_cmd = 1;
-               strvec_pushl(&cmd.args, "checkout", branch.buf, "--", NULL);
+               strvec_pushl(&cmd.args, "checkout", "--ignore-other-worktrees",
+                               branch.buf, "--", NULL);
                if (run_command(&cmd)) {
                        error(_("could not check out original"
                                " HEAD '%s'. Try 'git bisect"
index 3ba4fdf6153b69bce18bef335970742701b2dd34..fb01bd6abce2c815b6f50f75e27e2c8f567cf09c 100755 (executable)
@@ -122,6 +122,29 @@ test_expect_success 'bisect start without -- takes unknown arg as pathspec' '
        grep bar ".git/BISECT_NAMES"
 '
 
+test_expect_success 'bisect reset: back in a branch checked out also elsewhere' '
+       echo "shared" > branch.expect &&
+       test_bisect_reset() {
+               git -C $1 bisect start &&
+               git -C $1 bisect good $HASH1 &&
+               git -C $1 bisect bad $HASH3 &&
+               git -C $1 bisect reset &&
+               git -C $1 branch --show-current > branch.output &&
+               cmp branch.expect branch.output
+       } &&
+       test_when_finished "
+               git worktree remove wt1 &&
+               git worktree remove wt2 &&
+               git branch -d shared
+       " &&
+       git worktree add wt1 -b shared &&
+       git worktree add wt2 -f shared &&
+       # we test in both worktrees to ensure that works
+       # as expected with "first" and "next" worktrees
+       test_bisect_reset wt1 &&
+       test_bisect_reset wt2
+'
+
 test_expect_success 'bisect reset: back in the main branch' '
        git bisect reset &&
        echo "* main" > branch.expect &&