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

[PATCH 2/4] switch: allow to switch in the middle of bisect

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jun 20, 2019, 09:55 UTC
Message-ID
<20190620095523.10003-3-pclouds@gmail.com>
In-Reply-To
<20190620095523.10003-1-pclouds@gmail.com>

In c45f0f525d (switch: reject if some operation is in progress, 2019-03-29), a check is added to prevent switching when some operation is in progress. The reason is it's often not safe to do so.

This is true for merge, am, rebase, cherry-pick and revert, but not so much for bisect because bisecting is basically jumping/switching between a bunch of commits to pin point the first bad one. git-bisect suggests the next commit to test, but it's not wrong for the user to test a different commit because git-bisect cannot have the knowledge to know better.

For this reason, allow to switch when bisecting (*). I considered if we should still prevent switching by default and allow it with --ignore-in-progress. But I don't think the prevention really adds anything much.

If the user switches away by mistake, since we print the previous HEAD value, even if they don't know about the "-" shortcut, switching back is still possible.

The warning will be printed on every switch while bisect is still ongoing, not the first time you switch away from bisect's suggested commit, so it could become a bit annoying.

(*) of course when it's safe to do so, i.e. no loss of local changes and stuff.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/checkout.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index bed79ae595..f884d27f1f 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1326,9 +1326,7 @@ static void die_if_some_operation_in_progress(void)
 		      "Consider \"git revert --quit\" "
 		      "or \"git worktree add\"."));
 	if (state.bisect_in_progress)
-		die(_("cannot switch branch while bisecting\n"
-		      "Consider \"git bisect reset HEAD\" "
-		      "or \"git worktree add\"."));
+		warning(_("you are switching branch while bisecting"));
 }
 
 static int checkout_branch(struct checkout_opts *opts,
-- 
2.22.0.rc0.322.g2b0371e29a
Previous: Nguyễn Thái Ngọc DuyNext: Derrick Stolee
Message 3 of 13 in “Some more on top of nd/switch-and-restore”
  1. 0/4 Some more on top of nd/switch-and-restoreNguyễn Thái Ngọc Duy, Jun 20, 2019
  2. 1/4 t2027: use test_must_be_emptyNguyễn Thái Ngọc Duy, Jun 20, 2019
  3. 2/4 switch: allow to switch in the middle of bisectNguyễn Thái Ngọc Duy, Jun 20, 2019
  4. Derrick StoleeJun 20, 2019
  5. Duy NguyenJun 20, 2019
  6. 3/4 completion: disable dwim on "git switch -d"Nguyễn Thái Ngọc Duy, Jun 20, 2019
  7. 4/4 restore: add --intent-to-add (restoring worktree only)Nguyễn Thái Ngọc Duy, Jun 20, 2019
  8. Derrick StoleeJun 20, 2019
  9. Duy NguyenJun 20, 2019
  10. Junio C HamanoJun 26, 2019
  11. Duy NguyenJun 27, 2019
  12. Duy NguyenJun 27, 2019
  13. Junio C HamanoJun 27, 2019

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.