Revert "Merge branch 'hn/bisect-reset-when-found' into next"

This reverts commit 1dc394ad9ba2b7686d707341d0ed22c881999164, reversing changes made to 968a116891c15f6df5a7a84720f75c13a338b0f8. cf. <faa22968-54ac-4e4f-8324-3326ffb00c5b@kdbg.org>

Junio C Hamano committed Jul 29, 2026 at 11:40 UTC a29fc00619f0a9f65778174904356d07a893a305
4 files changed +21 -250
Documentation/git-bisect.adoc
+2 -12
@@ -10,7 +10,7 @@ SYNOPSIS
10 --------
11 [synopsis]
12 git bisect start [--term-(bad|new)=<term-new> --term-(good|old)=<term-old>]
13 - [--no-checkout] [--first-parent] [--reset-when-found[=<where>]] [<bad> [<good>...]] [--] [<pathspec>...]
13 + [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<pathspec>...]
14 git bisect (bad|new|<term-new>) [<rev>]
15 git bisect (good|old|<term-old>) [<rev>...]
16 git bisect terms [--term-(good|old) | --term-(bad|new)]
@@ -20,7 +20,7 @@ git bisect reset [<commit>]
20 git bisect (visualize|view)
21 git bisect replay <logfile>
22 git bisect log
23 -git bisect run [--reset-when-found[=<where>]] <cmd> [<arg>...]
23 +git bisect run <cmd> [<arg>...]
24 git bisect help
25
26 DESCRIPTION
@@ -385,16 +385,6 @@ ignored.
385 This option is particularly useful in avoiding false positives when a merged
386 branch contained broken or non-buildable commits, but the merge itself was OK.
387
388 -`--reset-when-found[=<where>]`::
389 - Once the first bad commit is found, report it and clean up the
390 - bisection state. `<where>` may be `original` to return to the commit
391 - checked out before `git bisect start`, or `found` to leave the first
392 - bad commit checked out. If `<where>` is omitted, it defaults to
393 - `original`.
394 -+
395 -This option may be given to `git bisect start` or to `git bisect run`. It
396 -cannot be used for a bisection started with `--no-checkout`.
397 -
388 EXAMPLES
389 --------
390
bisect.c
-2
@@ -488,7 +488,6 @@ static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
488 static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
489 static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
490 static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
491 -static GIT_PATH_FUNC(git_path_bisect_reset_when_found, "BISECT_RESET_WHEN_FOUND")
491
492 static void read_bisect_paths(struct strvec *array)
493 {
@@ -1212,7 +1211,6 @@ int bisect_clean_state(void)
1211 unlink_or_warn(git_path_bisect_run());
1212 unlink_or_warn(git_path_bisect_terms());
1213 unlink_or_warn(git_path_bisect_first_parent());
1215 - unlink_or_warn(git_path_bisect_reset_when_found());
1214 /*
1215 * Cleanup BISECT_START last to support the --no-checkout option
1216 * introduced in the commit 4796e823a.
builtin/bisect.c
+19 -127
@@ -24,12 +24,11 @@ static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
24 static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
25 static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
26 static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
27 -static GIT_PATH_FUNC(git_path_bisect_reset_when_found, "BISECT_RESET_WHEN_FOUND")
27 static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN")
28
29 #define BUILTIN_GIT_BISECT_START_USAGE \
30 N_("git bisect start [--term-(bad|new)=<term-new> --term-(good|old)=<term-old>]\n" \
32 - " [--no-checkout] [--first-parent] [--reset-when-found[=<where>]] [<bad> [<good>...]] [--] [<pathspec>...]")
31 + " [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<pathspec>...]")
32 #define BUILTIN_GIT_BISECT_BAD_USAGE \
33 N_("git bisect (bad|new|<term-new>) [<rev>]")
34 #define BUILTIN_GIT_BISECT_GOOD_USAGE \
@@ -49,7 +48,7 @@ static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN")
48 #define BUILTIN_GIT_BISECT_LOG_USAGE \
49 "git bisect log"
50 #define BUILTIN_GIT_BISECT_RUN_USAGE \
52 - N_("git bisect run [--reset-when-found[=<where>]] <cmd> [<arg>...]")
51 + N_("git bisect run <cmd> [<arg>...]")
52 #define BUILTIN_GIT_BISECT_HELP_USAGE \
53 "git bisect help"
54
@@ -69,12 +68,6 @@ static const char * const git_bisect_usage[] = {
68 NULL
69 };
70
72 -enum reset_when_found_mode {
73 - RESET_WHEN_FOUND_NONE,
74 - RESET_WHEN_FOUND_TO_ORIGINAL,
75 - RESET_WHEN_FOUND_TO_FOUND,
76 -};
77 -
71 struct add_bisect_ref_data {
72 struct rev_info *revs;
73 unsigned int object_flags;
@@ -241,7 +234,7 @@ static int write_terms(const char *bad, const char *good)
234 return res;
235 }
236
244 -static int bisect_reset(const char *commit, int quiet)
237 +static int bisect_reset(const char *commit)
238 {
239 struct strbuf branch = STRBUF_INIT;
240
@@ -262,10 +255,8 @@ static int bisect_reset(const char *commit, int quiet)
255 struct child_process cmd = CHILD_PROCESS_INIT;
256
257 cmd.git_cmd = 1;
265 - strvec_pushl(&cmd.args, "checkout", "--ignore-other-worktrees", NULL);
266 - if (quiet)
267 - strvec_push(&cmd.args, "--quiet");
268 - strvec_pushl(&cmd.args, branch.buf, "--", NULL);
258 + strvec_pushl(&cmd.args, "checkout", "--ignore-other-worktrees",
259 + branch.buf, "--", NULL);
260 if (run_command(&cmd)) {
261 error(_("could not check out original"
262 " HEAD '%s'. Try 'git bisect"
@@ -279,61 +270,6 @@ static int bisect_reset(const char *commit, int quiet)
270 return bisect_clean_state();
271 }
272
282 -static int parse_reset_when_found(const char *value,
283 - enum reset_when_found_mode *mode)
284 -{
285 - if (!strcmp(value, "original"))
286 - *mode = RESET_WHEN_FOUND_TO_ORIGINAL;
287 - else if (!strcmp(value, "found"))
288 - *mode = RESET_WHEN_FOUND_TO_FOUND;
289 - else
290 - return error(_("invalid value for '--reset-when-found': '%s'"),
291 - value);
292 -
293 - return 0;
294 -}
295 -
296 -static const char *reset_when_found_mode_name(enum reset_when_found_mode mode)
297 -{
298 - switch (mode) {
299 - case RESET_WHEN_FOUND_TO_ORIGINAL:
300 - return "original";
301 - case RESET_WHEN_FOUND_TO_FOUND:
302 - return "found";
303 - case RESET_WHEN_FOUND_NONE:
304 - BUG("no name for unset reset-when-found mode");
305 - }
306 - BUG("unknown reset-when-found mode %d", mode);
307 -}
308 -
309 -static int bisect_reset_when_found(struct bisect_terms *terms)
310 -{
311 - struct strbuf value = STRBUF_INIT;
312 - enum reset_when_found_mode mode;
313 - char *commit = NULL;
314 - int res;
315 -
316 - if (strbuf_read_file(&value, git_path_bisect_reset_when_found(), 0) < 0) {
317 - res = error_errno(_("could not read '%s'"),
318 - git_path_bisect_reset_when_found());
319 - goto cleanup;
320 - }
321 - strbuf_trim(&value);
322 - if (parse_reset_when_found(value.buf, &mode)) {
323 - res = -1;
324 - goto cleanup;
325 - }
326 -
327 - if (mode == RESET_WHEN_FOUND_TO_FOUND)
328 - commit = xstrfmt("refs/bisect/%s", terms->term_bad);
329 - res = bisect_reset(commit, 1);
330 -
331 -cleanup:
332 - free(commit);
333 - strbuf_release(&value);
334 - return res;
335 -}
336 -
273 static void log_commit(FILE *fp,
274 const char *fmt, const char *state,
275 struct commit *commit)
@@ -744,8 +680,7 @@ static int bisect_successful(struct bisect_terms *terms)
680 return res;
681 }
682
747 -static enum bisect_error bisect_next(struct bisect_terms *terms,
748 - const char *prefix, bool defer_reset)
683 +static enum bisect_error bisect_next(struct bisect_terms *terms, const char *prefix)
684 {
685 enum bisect_error res;
686
@@ -760,9 +695,6 @@ static enum bisect_error bisect_next(struct bisect_terms *terms,
695
696 if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND) {
697 res = bisect_successful(terms);
763 - if (!res && !defer_reset &&
764 - !is_empty_or_missing_file(git_path_bisect_reset_when_found()))
765 - res = bisect_reset_when_found(terms);
698 return res ? res : BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND;
699 } else if (res == BISECT_ONLY_SKIPPED_LEFT) {
700 res = bisect_skipped_commits(terms);
@@ -771,15 +703,14 @@ static enum bisect_error bisect_next(struct bisect_terms *terms,
703 return res;
704 }
705
774 -static enum bisect_error bisect_auto_next(struct bisect_terms *terms,
775 - const char *prefix, bool defer_reset)
706 +static enum bisect_error bisect_auto_next(struct bisect_terms *terms, const char *prefix)
707 {
708 if (bisect_next_check(terms, NULL)) {
709 bisect_print_status(terms);
710 return BISECT_OK;
711 }
712
782 - return bisect_next(terms, prefix, defer_reset);
713 + return bisect_next(terms, prefix);
714 }
715
716 static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
@@ -787,7 +718,6 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
718 {
719 int no_checkout = 0;
720 int first_parent_only = 0;
790 - enum reset_when_found_mode reset_when_found = RESET_WHEN_FOUND_NONE;
721 int i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0;
722 int flags, pathspec_pos;
723 enum bisect_error res = BISECT_OK;
@@ -820,13 +750,6 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
750 no_checkout = 1;
751 } else if (!strcmp(arg, "--first-parent")) {
752 first_parent_only = 1;
823 - } else if (!strcmp(arg, "--reset-when-found")) {
824 - reset_when_found = RESET_WHEN_FOUND_TO_ORIGINAL;
825 - } else if (skip_prefix(arg, "--reset-when-found=", &arg)) {
826 - if (parse_reset_when_found(arg, &reset_when_found)) {
827 - res = BISECT_FAILED;
828 - goto finish;
829 - }
753 } else if (!strcmp(arg, "--term-good") ||
754 !strcmp(arg, "--term-old")) {
755 i++;
@@ -864,10 +787,6 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
787 break;
788 }
789 }
867 - if (reset_when_found != RESET_WHEN_FOUND_NONE && no_checkout) {
868 - res = error(_("'--reset-when-found' cannot be used with '--no-checkout'"));
869 - goto finish;
870 - }
790 pathspec_pos = i;
791
792 /*
@@ -947,10 +866,6 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
866 if (first_parent_only)
867 write_file(git_path_bisect_first_parent(), "\n");
868
950 - if (reset_when_found != RESET_WHEN_FOUND_NONE)
951 - write_file(git_path_bisect_reset_when_found(), "%s\n",
952 - reset_when_found_mode_name(reset_when_found));
953 -
869 if (no_checkout) {
870 if (repo_get_oid(the_repository, start_head.buf, &oid) < 0) {
871 res = error(_("invalid ref: '%s'"), start_head.buf);
@@ -992,7 +907,7 @@ finish:
907 if (res)
908 return res;
909
995 - res = bisect_auto_next(terms, NULL, false);
910 + res = bisect_auto_next(terms, NULL);
911 if (!is_bisect_success(res))
912 bisect_clean_state();
913 return res;
@@ -1031,7 +946,7 @@ static int bisect_autostart(struct bisect_terms *terms)
946 }
947
948 static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
1034 - const char **argv, bool defer_reset)
949 + const char **argv)
950 {
951 const char *state;
952 int i, verify_expected = 1;
@@ -1108,7 +1023,7 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
1023 }
1024
1025 oid_array_clear(&revs);
1111 - return bisect_auto_next(terms, NULL, defer_reset);
1026 + return bisect_auto_next(terms, NULL);
1027 }
1028
1029 static enum bisect_error bisect_log(void)
@@ -1181,7 +1096,7 @@ static enum bisect_error bisect_replay(struct bisect_terms *terms, const char *f
1096 if (is_empty_or_missing_file(filename))
1097 return error(_("cannot read file '%s' for replaying"), filename);
1098
1184 - if (bisect_reset(NULL, 0))
1099 + if (bisect_reset(NULL))
1100 return BISECT_FAILED;
1101
1102 fp = fopen(filename, "r");
@@ -1197,7 +1112,7 @@ static enum bisect_error bisect_replay(struct bisect_terms *terms, const char *f
1112 if (res)
1113 return BISECT_FAILED;
1114
1200 - return bisect_auto_next(terms, NULL, false);
1115 + return bisect_auto_next(terms, NULL);
1116 }
1117
1118 static enum bisect_error bisect_skip(struct bisect_terms *terms, int argc,
@@ -1231,7 +1146,7 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, int argc,
1146 strvec_push(&argv_state, argv[i]);
1147 }
1148 }
1234 - res = bisect_state(terms, argv_state.nr, argv_state.v, false);
1149 + res = bisect_state(terms, argv_state.nr, argv_state.v);
1150
1151 strvec_clear(&argv_state);
1152 return res;
@@ -1329,8 +1244,6 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)
1244 {
1245 int res = BISECT_OK;
1246 struct strbuf command = STRBUF_INIT;
1332 - enum reset_when_found_mode reset_when_found = RESET_WHEN_FOUND_NONE;
1333 - const char *reset_when_found_arg;
1247 const char *new_state;
1248 int temporary_stdout_fd, saved_stdout;
1249 int is_first_run = 1;
@@ -1338,23 +1251,6 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)
1251 if (bisect_next_check(terms, NULL))
1252 return BISECT_FAILED;
1253
1341 - if (argc && !strcmp(argv[0], "--reset-when-found"))
1342 - reset_when_found = RESET_WHEN_FOUND_TO_ORIGINAL;
1343 - else if (argc && skip_prefix(argv[0], "--reset-when-found=",
1344 - &reset_when_found_arg)) {
1345 - if (parse_reset_when_found(reset_when_found_arg, &reset_when_found))
1346 - return BISECT_FAILED;
1347 - }
1348 -
1349 - if (reset_when_found != RESET_WHEN_FOUND_NONE) {
1350 - if (refs_ref_exists(get_main_ref_store(the_repository), "BISECT_HEAD"))
1351 - return error(_("'--reset-when-found' cannot be used with '--no-checkout'"));
1352 - write_file(git_path_bisect_reset_when_found(), "%s\n",
1353 - reset_when_found_mode_name(reset_when_found));
1354 - argc--;
1355 - argv++;
1356 - }
1357 -
1254 if (!argc) {
1255 error(_("bisect run failed: no command provided."));
1256 return BISECT_FAILED;
@@ -1413,7 +1309,7 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)
1309 saved_stdout = dup(1);
1310 dup2(temporary_stdout_fd, 1);
1311
1416 - res = bisect_state(terms, 1, &new_state, true);
1312 + res = bisect_state(terms, 1, &new_state);
1313
1314 fflush(stdout);
1315 dup2(saved_stdout, 1);
@@ -1429,11 +1325,7 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)
1325 res = BISECT_OK;
1326 } else if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND) {
1327 printf(_("bisect found first '%s' commit\n"), terms->term_bad);
1432 - if (!is_empty_or_missing_file(git_path_bisect_reset_when_found()) &&
1433 - bisect_reset_when_found(terms))
1434 - res = BISECT_FAILED;
1435 - else
1436 - res = BISECT_OK;
1328 + res = BISECT_OK;
1329 } else if (res) {
1330 error(_("bisect run failed: 'git bisect %s'"
1331 " exited with error code %d"), new_state, res);
@@ -1453,7 +1345,7 @@ static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNU
1345 if (argc > 1)
1346 return error(_("'%s' requires either no argument or a commit"),
1347 "git bisect reset");
1456 - return bisect_reset(argc ? argv[0] : NULL, 0);
1348 + return bisect_reset(argc ? argv[0] : NULL);
1349 }
1350
1351 static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED,
@@ -1492,7 +1384,7 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
1384 return error(_("'%s' requires 0 arguments"),
1385 "git bisect next");
1386 get_terms(&terms);
1495 - res = bisect_next(&terms, prefix, false);
1387 + res = bisect_next(&terms, prefix);
1388 free_terms(&terms);
1389 return res;
1390 }
@@ -1595,7 +1487,7 @@ int cmd_bisect(int argc,
1487 !one_of(argv[0], terms.term_good, terms.term_bad, NULL))
1488 usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,
1489 options, argv[0]);
1598 - res = bisect_state(&terms, argc, argv, false);
1490 + res = bisect_state(&terms, argc, argv);
1491 free_terms(&terms);
1492 } else {
1493 argc--;
t/t6030-bisect-porcelain.sh
-109
@@ -43,38 +43,6 @@ test_bisect_usage () {
43 test_cmp expect actual
44 }
45
46 -test_bisect_state_file () {
47 - test_path_is_file "$(git rev-parse --git-path "$1")"
48 -}
49 -
50 -test_bisect_state_missing () {
51 - test_path_is_missing "$(git rev-parse --git-path "$1")"
52 -}
53 -
54 -bisect_start_and_finish () {
55 - git bisect start "$1" $HASH4 $HASH2 &&
56 - git bisect bad
57 -}
58 -
59 -bisect_run_reset_when_found () {
60 - write_script test_script.sh <<-\EOF &&
61 - ! grep Another hello >/dev/null
62 - EOF
63 - git bisect start $HASH4 $HASH2 &&
64 - git bisect run "$1" ./test_script.sh >my_bisect_log.txt &&
65 - test_grep "$HASH3 is the first .bad. commit" my_bisect_log.txt &&
66 - test_bisect_state_missing BISECT_RUN
67 -}
68 -
69 -test_reset_when_found_fails () {
70 - local pattern="$1" &&
71 - local state_file="$2" &&
72 - shift 2 &&
73 - test_must_fail "$@" 2>err &&
74 - test_grep -- "$pattern" err &&
75 - test_bisect_state_missing "$state_file"
76 -}
77 -
46 test_expect_success 'bisect usage' "
47 test_bisect_usage 1 git bisect reset extra1 extra2 <<-\EOF &&
48 error: 'git bisect reset' requires either no argument or a commit
@@ -485,83 +453,6 @@ test_expect_success '"git bisect run" simple case' '
453 git bisect reset
454 '
455
488 -test_expect_success '"git bisect start --reset-when-found" defaults to original' '
489 - test_when_finished "git bisect reset; git checkout main" &&
490 - git checkout main &&
491 - bisect_start_and_finish --reset-when-found &&
492 - test "$HASH4" = "$(git rev-parse HEAD)" &&
493 - test main = "$(git branch --show-current)" &&
494 - test_bisect_state_missing BISECT_START &&
495 -
496 - bisect_start_and_finish --reset-when-found=original &&
497 - test "$HASH4" = "$(git rev-parse HEAD)" &&
498 - test main = "$(git branch --show-current)" &&
499 - test_bisect_state_missing BISECT_START
500 -'
501 -
502 -test_expect_success '"git bisect start --reset-when-found=found" leaves first bad checked out' '
503 - test_when_finished "git bisect reset; git checkout main" &&
504 - bisect_start_and_finish --reset-when-found=found &&
505 - test "$HASH3" = "$(git rev-parse HEAD)" &&
506 - test_bisect_state_missing BISECT_START
507 -'
508 -
509 -test_expect_success '"git bisect run --reset-when-found" defaults to original' '
510 - test_when_finished "git bisect reset; git checkout main" &&
511 - bisect_run_reset_when_found --reset-when-found &&
512 - test "$HASH4" = "$(git rev-parse HEAD)" &&
513 - test main = "$(git branch --show-current)" &&
514 - test_bisect_state_missing BISECT_START
515 -'
516 -
517 -test_expect_success '"git bisect run --reset-when-found=found" leaves first bad checked out' '
518 - test_when_finished "git bisect reset; git checkout main" &&
519 - bisect_run_reset_when_found --reset-when-found=found &&
520 - test "$HASH3" = "$(git rev-parse HEAD)" &&
521 - test_bisect_state_missing BISECT_START
522 -'
523 -
524 -test_expect_success '--reset-when-found rejects an unknown reset target' '
525 - test_when_finished "git bisect reset; git checkout main" &&
526 - test_reset_when_found_fails \
527 - "invalid value for.*--reset-when-found.*unknown" BISECT_START \
528 - git bisect start --reset-when-found=unknown $HASH4 $HASH2 &&
529 -
530 - git bisect start $HASH4 $HASH2 &&
531 - test_reset_when_found_fails \
532 - "invalid value for.*--reset-when-found.*unknown" \
533 - BISECT_RESET_WHEN_FOUND \
534 - git bisect run --reset-when-found=unknown true
535 -'
536 -
537 -test_expect_success '--reset-when-found cannot be used with --no-checkout' '
538 - test_when_finished "git bisect reset" &&
539 - test_reset_when_found_fails \
540 - "cannot be used with.*--no-checkout" BISECT_START \
541 - git bisect start --reset-when-found=original --no-checkout $HASH4 $HASH2 &&
542 -
543 - git bisect start --no-checkout $HASH4 $HASH2 &&
544 - test_reset_when_found_fails \
545 - "cannot be used with.*--no-checkout" BISECT_RESET_WHEN_FOUND \
546 - git bisect run --reset-when-found=found true
547 -'
548 -
549 -test_expect_success 'without --reset-when-found the bisection state is kept' '
550 - test_when_finished "git bisect reset" &&
551 - git bisect start $HASH4 $HASH2 &&
552 - git bisect bad &&
553 - test_bisect_state_file BISECT_START
554 -'
555 -
556 -test_expect_success '--reset-when-found does not leak into a later bisection' '
557 - test_when_finished "git bisect reset; git checkout main" &&
558 - bisect_start_and_finish --reset-when-found &&
559 -
560 - git bisect start $HASH4 $HASH2 &&
561 - git bisect bad &&
562 - test_bisect_state_file BISECT_START
563 -'
564 -
456 # We want to automatically find the commit that
457 # added "Ciao" into hello.
458 test_expect_success '"git bisect run" with more complex "git bisect start"' '