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

Re: [PATCH v3 2/2] bisect: add --reset-when-found to leave when done

From
Johannes Sixt <j6t@kdbg.org>
Date
Jul 23, 2026, 09:17 UTC
Message-ID
<faa22968-54ac-4e4f-8324-3326ffb00c5b@kdbg.org>
In-Reply-To
<542f4b2c8065818b887437add90130d2090fa0f2.1784538619.git.gitgitgadget@gmail.com>
Am 20.07.26 um 11:10 schrieb Harald Nordgren via GitGitGadget:
Show 6 quoted lines
> @@ -784,6 +859,10 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
>  			break;
>  		}
>  	}
> +	if (reset_when_found != RESET_WHEN_FOUND_NONE && no_checkout) {
> +		res = error(_("'--reset-when-found' cannot be used with '--no-checkout'"));
We have a boilerplate text for this kind of error that saves a translation:
		res = error(_("options '%s' and '%s' cannot be used together"),
"--reset-when-found", "--no-checkout");
Show 5 quoted lines
> +		goto finish;
> +	}
>  	pathspec_pos = i;
>  
>  	/*
Show 15 quoted lines
> @@ -1246,6 +1331,23 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)
>  	if (bisect_next_check(terms, NULL))
>  		return BISECT_FAILED;
>  
> +	if (argc && !strcmp(argv[0], "--reset-when-found"))
> +		reset_when_found = RESET_WHEN_FOUND_TO_ORIGINAL;
> +	else if (argc && skip_prefix(argv[0], "--reset-when-found=",
> +				    &reset_when_found_arg)) {
> +		if (parse_reset_when_found(reset_when_found_arg, &reset_when_found))
> +			return BISECT_FAILED;
> +	}
> +
> +	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'"));
Ditto.
Show 9 quoted lines
> +		write_file(git_path_bisect_reset_when_found(), "%s\n",
> +			   reset_when_found_mode_name(reset_when_found));
> +		argc--;
> +		argv++;
> +	}
> +
>  	if (!argc) {
>  		error(_("bisect run failed: no command provided."));
>  		return BISECT_FAILED;
Show 15 quoted lines
> diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
> index 081116220a..7dfb871ab9 100755
> --- a/t/t6030-bisect-porcelain.sh
> +++ b/t/t6030-bisect-porcelain.sh
> @@ -43,6 +43,38 @@ test_bisect_usage () {
>  	test_cmp expect actual
>  }
>  
> +test_bisect_state_file () {
> +	test_path_is_file "$(git rev-parse --git-path "$1")"
> +}
> +
> +test_bisect_state_missing () {
> +	test_path_is_missing "$(git rev-parse --git-path "$1")"
> +}

These should not use `git` in a $( ) subshell to avoid a case of "ignore failure in upstream of pipe". Note that

	local file=$(git rev-parse ...) &&
	test_path...
would be wrong, too, for the same reason. But
	local file
	file=$(git rev-parse ...) &&
	test_path...
works as desired.
> +test_expect_success '"git bisect start --reset-when-found" defaults to original' '
> +	test_when_finished "git bisect reset; git checkout main" &&

Looking at other cases where more than one git command is invoked by test_when_finished, it seems that they are chained with '&&'. `git grepc "&& git checkout main"` does find a few hits.

Show 11 quoted lines
> +	git checkout main &&
> +	bisect_start_and_finish --reset-when-found &&
> +	test "$HASH4" = "$(git rev-parse HEAD)" &&
> +	test main = "$(git branch --show-current)" &&
> +	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)" &&
> +	test_bisect_state_missing BISECT_START
> +'

More cases of `git` in a subshell above and below. I notice that you are mimicking existing practice in this file. I'm torn whether to change this or not. After all, there are also a lot of cases in the file that uses the correct pattern where the subshell is in a variable assignment.

Show 22 quoted lines
> +
> +test_expect_success '"git bisect start --reset-when-found=found" leaves first bad checked out' '
> +	test_when_finished "git bisect reset; git checkout main" &&
> +	bisect_start_and_finish --reset-when-found=found &&
> +	test "$HASH3" = "$(git rev-parse HEAD)" &&
> +	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" &&
> +	bisect_run_reset_when_found --reset-when-found &&
> +	test "$HASH4" = "$(git rev-parse HEAD)" &&
> +	test main = "$(git branch --show-current)" &&
> +	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" &&
> +	bisect_run_reset_when_found --reset-when-found=found &&
> +	test "$HASH3" = "$(git rev-parse HEAD)" &&
> +	test_bisect_state_missing BISECT_START
> +'
-- Hannes
Previous: Harald Nordgren via GitGitGadgetNext: Junio C Hamano
Message 21 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.