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

[PATCH v4 0/2] bisect: add --reset-when-found to leave when done

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 1, 2026, 09:44 UTC
Message-ID
<pull.2335.v4.git.git.1785577445.gitgitgadget@gmail.com>
In-Reply-To
<pull.2335.v3.git.git.1784538619.gitgitgadget@gmail.com>

Add a --reset-when-found option to git bisect that resets the bisect session when culprit is found.

Changes in v4:
 * Simplify translation calls.
 * Avoid git subshell calls in tests, that can bury errors.
Changes in v3:
 * Rename --auto-reset to --reset-when-found, including internal names.
 * Defer git bisect run cleanup until captured output is printed and
   BISECT_RUN is closed. Drop the open-descriptor preparatory change,
   retaining the existing filename-based output handling.
Changes in v2:
 * Add option --auto-reset[=<where>] with option to go to final commit as
   well as original.
 * Refactored tests.
Harald Nordgren (2):
  bisect: let bisect_reset() optionally check out quietly
  bisect: add --reset-when-found to leave when done
 Documentation/git-bisect.adoc |  14 +++-
 bisect.c                      |   2 +
 builtin/bisect.c              | 148 +++++++++++++++++++++++++++++-----
 t/t6030-bisect-porcelain.sh   | 121 +++++++++++++++++++++++++++
 4 files changed, 264 insertions(+), 21 deletions(-)
base-commit: a97fcc37c2bc6340a8d7ce78dedf227aac4e9aa7
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2335%2FHaraldNordgren%2Fbisect-auto-reset-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2335/HaraldNordgren/bisect-auto-reset-v4
Pull-Request: https://github.com/git/git/pull/2335
Range-diff vs v3:
 1:  59920c51ae = 1:  e39670edf4 bisect: let bisect_reset() optionally check out quietly
 2:  542f4b2c80 ! 2:  f5f370df1b bisect: add --reset-when-found to leave when done
     @@ builtin/bisect.c: static enum bisect_error bisect_start(struct bisect_terms *ter
       		}
       	}
      +	if (reset_when_found != RESET_WHEN_FOUND_NONE && no_checkout) {
     -+		res = error(_("'--reset-when-found' cannot be used with '--no-checkout'"));
     ++		res = error(_("options '%s' and '%s' cannot be used together"),
     ++			    "--reset-when-found", "--no-checkout");
      +		goto finish;
      +	}
       	pathspec_pos = i;
     @@ builtin/bisect.c: static int bisect_run(struct bisect_terms *terms, int argc, co
      +
      +	if (reset_when_found != RESET_WHEN_FOUND_NONE) {
      +		if (refs_ref_exists(get_main_ref_store(the_repository), "BISECT_HEAD"))
     -+			return error(_("'--reset-when-found' cannot be used with '--no-checkout'"));
     ++			return error(_("options '%s' and '%s' cannot be used together"),
     ++				     "--reset-when-found", "--no-checkout");
      +		write_file(git_path_bisect_reset_when_found(), "%s\n",
      +			   reset_when_found_mode_name(reset_when_found));
      +		argc--;
     @@ t/t6030-bisect-porcelain.sh: test_bisect_usage () {
       }
       
      +test_bisect_state_file () {
     -+	test_path_is_file "$(git rev-parse --git-path "$1")"
     ++	local file &&
     ++	file=$(git rev-parse --git-path "$1") &&
     ++	test_path_is_file "$file"
      +}
      +
      +test_bisect_state_missing () {
     -+	test_path_is_missing "$(git rev-parse --git-path "$1")"
     ++	local file &&
     ++	file=$(git rev-parse --git-path "$1") &&
     ++	test_path_is_missing "$file"
      +}
      +
      +bisect_start_and_finish () {
     @@ t/t6030-bisect-porcelain.sh: test_expect_success '"git bisect run" simple case'
       '
       
      +test_expect_success '"git bisect start --reset-when-found" defaults to original' '
     -+	test_when_finished "git bisect reset; git checkout main" &&
     ++	test_when_finished "git bisect reset && git checkout main" &&
      +	git checkout main &&
      +	bisect_start_and_finish --reset-when-found &&
     -+	test "$HASH4" = "$(git rev-parse HEAD)" &&
     -+	test main = "$(git branch --show-current)" &&
     ++	actual=$(git rev-parse HEAD) &&
     ++	test "$HASH4" = "$actual" &&
     ++	actual=$(git branch --show-current) &&
     ++	test main = "$actual" &&
      +	test_bisect_state_missing BISECT_START &&
      +
      +	bisect_start_and_finish --reset-when-found=original &&
     -+	test "$HASH4" = "$(git rev-parse HEAD)" &&
     -+	test main = "$(git branch --show-current)" &&
     ++	actual=$(git rev-parse HEAD) &&
     ++	test "$HASH4" = "$actual" &&
     ++	actual=$(git branch --show-current) &&
     ++	test main = "$actual" &&
      +	test_bisect_state_missing BISECT_START
      +'
      +
      +test_expect_success '"git bisect start --reset-when-found=found" leaves first bad checked out' '
     -+	test_when_finished "git bisect reset; git checkout main" &&
     ++	test_when_finished "git bisect reset && git checkout main" &&
      +	bisect_start_and_finish --reset-when-found=found &&
     -+	test "$HASH3" = "$(git rev-parse HEAD)" &&
     ++	actual=$(git rev-parse HEAD) &&
     ++	test "$HASH3" = "$actual" &&
      +	test_bisect_state_missing BISECT_START
      +'
      +
      +test_expect_success '"git bisect run --reset-when-found" defaults to original' '
     -+	test_when_finished "git bisect reset; git checkout main" &&
     ++	test_when_finished "git bisect reset && git checkout main" &&
      +	bisect_run_reset_when_found --reset-when-found &&
     -+	test "$HASH4" = "$(git rev-parse HEAD)" &&
     -+	test main = "$(git branch --show-current)" &&
     ++	actual=$(git rev-parse HEAD) &&
     ++	test "$HASH4" = "$actual" &&
     ++	actual=$(git branch --show-current) &&
     ++	test main = "$actual" &&
      +	test_bisect_state_missing BISECT_START
      +'
      +
      +test_expect_success '"git bisect run --reset-when-found=found" leaves first bad checked out' '
     -+	test_when_finished "git bisect reset; git checkout main" &&
     ++	test_when_finished "git bisect reset && git checkout main" &&
      +	bisect_run_reset_when_found --reset-when-found=found &&
     -+	test "$HASH3" = "$(git rev-parse HEAD)" &&
     ++	actual=$(git rev-parse HEAD) &&
     ++	test "$HASH3" = "$actual" &&
      +	test_bisect_state_missing BISECT_START
      +'
      +
      +test_expect_success '--reset-when-found rejects an unknown reset target' '
     -+	test_when_finished "git bisect reset; git checkout main" &&
     ++	test_when_finished "git bisect reset && git checkout main" &&
      +	test_reset_when_found_fails \
      +		"invalid value for.*--reset-when-found.*unknown" BISECT_START \
      +		git bisect start --reset-when-found=unknown $HASH4 $HASH2 &&
     @@ t/t6030-bisect-porcelain.sh: test_expect_success '"git bisect run" simple case'
      +test_expect_success '--reset-when-found cannot be used with --no-checkout' '
      +	test_when_finished "git bisect reset" &&
      +	test_reset_when_found_fails \
     -+		"cannot be used with.*--no-checkout" BISECT_START \
     ++		"options .*--reset-when-found.* and .*--no-checkout.* cannot be used together" BISECT_START \
      +		git bisect start --reset-when-found=original --no-checkout $HASH4 $HASH2 &&
      +
      +	git bisect start --no-checkout $HASH4 $HASH2 &&
      +	test_reset_when_found_fails \
     -+		"cannot be used with.*--no-checkout" BISECT_RESET_WHEN_FOUND \
     ++		"options .*--reset-when-found.* and .*--no-checkout.* cannot be used together" BISECT_RESET_WHEN_FOUND \
      +		git bisect run --reset-when-found=found true
      +'
      +
     @@ t/t6030-bisect-porcelain.sh: test_expect_success '"git bisect run" simple case'
      +'
      +
      +test_expect_success '--reset-when-found does not leak into a later bisection' '
     -+	test_when_finished "git bisect reset; git checkout main" &&
     ++	test_when_finished "git bisect reset && git checkout main" &&
      +	bisect_start_and_finish --reset-when-found &&
      +
      +	git bisect start $HASH4 $HASH2 &&
-- 
gitgitgadget
Previous: Junio C HamanoNext: Harald Nordgren via GitGitGadget
Message 25 of 42 in “bisect: add --auto-reset to leave when done”
  1. 0/3 bisect: add --auto-reset to leave when doneHarald Nordgren via GitGitGadget, Jul 16, 2026
  2. 1/3 bisect: read run output from the open descriptorHarald Nordgren via GitGitGadget, Jul 16, 2026
  3. 2/3 bisect: let bisect_reset() optionally check out quietlyHarald Nordgren via GitGitGadget, Jul 16, 2026
  4. 3/3 bisect: add --auto-reset to leave when doneHarald Nordgren via GitGitGadget, Jul 16, 2026
  5. Junio C HamanoJul 16, 2026
  6. Harald NordgrenJul 16, 2026
  7. Junio C HamanoJul 17, 2026
  8. Harald NordgrenJul 17, 2026
  9. Junio C HamanoJul 17, 2026
  10. 0/3 bisect: add --auto-reset to leave when doneHarald Nordgren via GitGitGadget, Jul 17, 2026
  11. 1/3 bisect: read run output from the open descriptorHarald Nordgren via GitGitGadget, Jul 17, 2026
  12. Junio C HamanoJul 17, 2026
  13. Johannes SixtJul 18, 2026
  14. 2/3 bisect: let bisect_reset() optionally check out quietlyHarald Nordgren via GitGitGadget, Jul 17, 2026
  15. 3/3 bisect: add --auto-reset to leave when doneHarald Nordgren via GitGitGadget, Jul 17, 2026
  16. Johannes SixtJul 18, 2026
  17. Junio C HamanoJul 20, 2026
  18. 0/2 bisect: add --auto-reset to leave when doneHarald Nordgren via GitGitGadget, Jul 20, 2026
  19. 1/2 bisect: let bisect_reset() optionally check out quietlyHarald Nordgren via GitGitGadget, Jul 20, 2026
  20. 2/2 bisect: add --reset-when-found to leave when doneHarald Nordgren via GitGitGadget, Jul 20, 2026
  21. Johannes SixtJul 23, 2026
  22. Junio C HamanoJul 23, 2026
  23. Harald NordgrenAug 1, 2026
  24. Junio C HamanoJul 20, 2026
  25. 0/2 bisect: add --reset-when-found to leave when doneHarald Nordgren via GitGitGadget, Aug 1, 2026
  26. 1/2 bisect: let bisect_reset() optionally check out quietlyHarald Nordgren via GitGitGadget, Aug 1, 2026
  27. Junio C HamanoAug 1, 2026
  28. 2/2 bisect: add --reset-when-found to leave when doneHarald Nordgren via GitGitGadget, Aug 1, 2026
  29. Junio C HamanoAug 1, 2026
  30. Junio C HamanoAug 1, 2026
  31. 0/2 bisect: add --reset-when-found to leave when doneHarald Nordgren via GitGitGadget, Aug 2, 2026
  32. 1/2 bisect: let bisect_reset() optionally check out quietlyHarald Nordgren via GitGitGadget, Aug 2, 2026
  33. 2/2 bisect: add --reset-when-found to leave when doneHarald Nordgren via GitGitGadget, Aug 2, 2026
  34. Junio C HamanoAug 2, 2026
  35. 0/2 bisect: add --reset-when-found to leave when doneHarald Nordgren via GitGitGadget, Aug 2, 2026
  36. 1/2 bisect: let bisect_reset() optionally check out quietlyHarald Nordgren via GitGitGadget, Aug 2, 2026
  37. 2/2 bisect: add --reset-when-found to leave when doneHarald Nordgren via GitGitGadget, Aug 2, 2026
  38. Junio C HamanoAug 3, 2026
  39. Harald NordgrenAug 6, 2026
  40. Junio C HamanoAug 6, 2026
  41. Harald NordgrenAug 6, 2026
  42. Junio C HamanoAug 6, 2026

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.