git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] bisect: fix "reset" when branch is checked out elsewhere

From
Rubén Justo <rjusto@gmail.com>
Date
Feb 4, 2023, 22:57 UTC
Message-ID
<ada28944-6e9e-d4e7-74c9-ffadaf406e1f@gmail.com>
In-Reply-To
<1c36c334-9f10-3859-c92f-3d889e226769@gmail.com>

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>
---
Range-diff against v1:
1:  f902db6bfb ! 1:  72e1526313 bisect: fix "reset" when branch is checked out elsewhere
    @@ builtin/bisect.c: static int bisect_reset(const char *commit)
      
      		cmd.git_cmd = 1;
     -		strvec_pushl(&cmd.args, "checkout", branch.buf, "--", NULL);
    -+		strvec_pushl(&cmd.args, "checkout", "--ignore-other-worktrees",
    -+				branch.buf, "--", NULL);
    ++		strvec_pushl(&cmd.args, "checkout", NULL);
    ++		if (!commit)
    ++			strvec_pushl(&cmd.args, "--ignore-other-worktrees", NULL);
    ++		strvec_pushl(&cmd.args, branch.buf, "--", NULL);
      		if (run_command(&cmd)) {
      			error(_("could not check out original"
      				" HEAD '%s'. Try 'git bisect"
 builtin/bisect.c            |  5 ++++-
 t/t6030-bisect-porcelain.sh | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 7301740267..46fba8db50 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -244,7 +244,10 @@ 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", NULL);
+		if (!commit)
+			strvec_pushl(&cmd.args, "--ignore-other-worktrees", NULL);
+		strvec_pushl(&cmd.args, branch.buf, "--", NULL);
 		if (run_command(&cmd)) {
 			error(_("could not check out original"
 				" HEAD '%s'. Try 'git bisect"
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 3ba4fdf615..fb01bd6abc 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -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 &&
-- 
2.39.0
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 15 in “bisect: fix "reset" when branch is checked out elsewhere”
  1. bisect: fix "reset" when branch is checked out elsewhereRubén Justo, Jan 22, 2023
  2. Junio C HamanoJan 23, 2023
  3. Rubén JustoJan 26, 2023
  4. Junio C HamanoJan 26, 2023
  5. Junio C HamanoJan 26, 2023
  6. Rubén JustoFeb 4, 2023
  7. Junio C HamanoFeb 6, 2023
  8. bisect: fix "reset" when branch is checked out elsewhereRubén Justo, Feb 4, 2023
  9. Junio C HamanoFeb 6, 2023
  10. Rubén JustoFeb 8, 2023
  11. Junio C HamanoFeb 8, 2023
  12. Rubén JustoFeb 8, 2023
  13. Eric SunshineFeb 15, 2023
  14. Rubén JustoFeb 15, 2023
  15. bisect: fix "reset" when branch is checked out elsewhereRubén Justo, Feb 20, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.