rev-parse: use selected alternate terms to look up refs

git rev-parse --bisect does not work when alternate bisect terms are used, simply listing no revisions at all. This is because a such bisect using e.g. "old" and "new" in place of "good" and "bad" will name refs "refs/bisect/old" (or new) accordingly so the hardcoded "refs/bisect/bad" (and good) yields no results in a bisect using alternate terms. Use the current bisect_terms to make rev-parse --bisect work in an alternate term bisect. Signed-off-by: Jonas Rebmann <kernel@schlaraffenlan.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonas Rebmann committed May 14, 2026 at 11:07 UTC cb559918253d636dc00afa8cb468a810c1f4347b
2 files changed +38 -2
builtin/rev-parse.c
+13 -2
@@ -10,6 +10,7 @@
10 #include "builtin.h"
11
12 #include "abspath.h"
13 +#include "bisect.h"
14 #include "config.h"
15 #include "commit.h"
16 #include "environment.h"
@@ -940,13 +941,23 @@ int cmd_rev_parse(int argc,
941 continue;
942 }
943 if (!strcmp(arg, "--bisect")) {
944 + char *prefix;
945 + char *term_bad = NULL;
946 + char *term_good = NULL;
947 struct refs_for_each_ref_options opts = { 0 };
944 - opts.prefix = "refs/bisect/bad";
948 + read_bisect_terms(&term_bad, &term_good);
949 + prefix = xstrfmt("refs/bisect/%s", term_bad);
950 + opts.prefix = prefix;
951 refs_for_each_ref_ext(get_main_ref_store(the_repository),
952 show_reference, NULL, &opts);
947 - opts.prefix = "refs/bisect/good";
953 + free(prefix);
954 + prefix = xstrfmt("refs/bisect/%s", term_good);
955 + opts.prefix = prefix;
956 refs_for_each_ref_ext(get_main_ref_store(the_repository),
957 anti_reference, NULL, &opts);
958 + free(prefix);
959 + free(term_good);
960 + free(term_bad);
961 continue;
962 }
963 if (opt_with_value(arg, "--branches", &arg)) {
t/t1500-rev-parse.sh
+25
@@ -337,6 +337,31 @@ test_expect_success 'rev-parse --bisect includes bad, excludes good' '
337 test_cmp expect actual
338 '
339
340 +test_expect_success 'rev-parse --bisect works with alternate terms' '
341 + test_commit_bulk 6 &&
342 +
343 + git bisect start --term-old=known --term-new=curious &&
344 +
345 + git update-ref refs/bisect/curious-1 HEAD~1 &&
346 + git update-ref refs/bisect/bad HEAD~2 &&
347 + git update-ref refs/bisect/curious-3 HEAD~3 &&
348 + git update-ref refs/bisect/known-3 HEAD~3 &&
349 + git update-ref refs/bisect/curious-4 HEAD~4 &&
350 + git update-ref refs/bisect/good HEAD~4 &&
351 +
352 + # Note: refs/bisect/bad and refs/bisect/goood should be ignored because this
353 + # is a bisect with custom terms (known/curious)
354 + cat >expect <<-EOF &&
355 + refs/bisect/curious-1
356 + refs/bisect/curious-3
357 + refs/bisect/curious-4
358 + ^refs/bisect/known-3
359 + EOF
360 +
361 + git rev-parse --symbolic-full-name --bisect >actual &&
362 + test_cmp expect actual
363 +'
364 +
365 test_expect_success '--short= truncates to the actual hash length' '
366 git rev-parse HEAD >expect &&
367 git rev-parse --short=100 HEAD >actual &&