]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rev-parse: use selected alternate terms to look up refs
authorJonas Rebmann <kernel@schlaraffenlan.de>
Fri, 17 Apr 2026 16:48:31 +0000 (18:48 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Apr 2026 19:04:59 +0000 (12:04 -0700)
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>
builtin/rev-parse.c
t/t1500-rev-parse.sh

index 01a62800e879380defdab9d0e16684adc5b387a1..e6bda8db6cd24e62057d9c6981f1bcd4f7f2856a 100644 (file)
@@ -10,6 +10,7 @@
 #include "builtin.h"
 
 #include "abspath.h"
+#include "bisect.h"
 #include "config.h"
 #include "commit.h"
 #include "environment.h"
@@ -940,13 +941,23 @@ int cmd_rev_parse(int argc,
                                continue;
                        }
                        if (!strcmp(arg, "--bisect")) {
+                               char *prefix;
+                               char *term_bad = NULL;
+                               char *term_good = NULL;
                                struct refs_for_each_ref_options opts = { 0 };
-                               opts.prefix = "refs/bisect/bad";
+                               read_bisect_terms(&term_bad, &term_good);
+                               prefix = xstrfmt("refs/bisect/%s", term_bad);
+                               opts.prefix = prefix;
                                refs_for_each_ref_ext(get_main_ref_store(the_repository),
                                                      show_reference, NULL, &opts);
-                               opts.prefix = "refs/bisect/good";
+                               free(prefix);
+                               prefix = xstrfmt("refs/bisect/%s", term_good);
+                               opts.prefix = prefix;
                                refs_for_each_ref_ext(get_main_ref_store(the_repository),
                                                      anti_reference, NULL, &opts);
+                               free(prefix);
+                               free(term_good);
+                               free(term_bad);
                                continue;
                        }
                        if (opt_with_value(arg, "--branches", &arg)) {
index 98c5a772bdad8de3552b750b0f7e3f67b096bafd..38067d95f7f12b031fff8c86deee951c7a6c898e 100755 (executable)
@@ -337,6 +337,31 @@ test_expect_success 'rev-parse --bisect includes bad, excludes good' '
        test_cmp expect actual
 '
 
+test_expect_success 'rev-parse --bisect works with alternate terms' '
+       test_commit_bulk 6 &&
+
+       git bisect start --term-old=known --term-new=curious &&
+
+       git update-ref refs/bisect/curious-1 HEAD~1 &&
+       git update-ref refs/bisect/bad HEAD~2 &&
+       git update-ref refs/bisect/curious-3 HEAD~3 &&
+       git update-ref refs/bisect/known-3 HEAD~3 &&
+       git update-ref refs/bisect/curious-4 HEAD~4 &&
+       git update-ref refs/bisect/good HEAD~4 &&
+
+       # Note: refs/bisect/bad and refs/bisect/goood should be ignored because this
+       # is a bisect with custom terms (known/curious)
+       cat >expect <<-EOF &&
+       refs/bisect/curious-1
+       refs/bisect/curious-3
+       refs/bisect/curious-4
+       ^refs/bisect/known-3
+       EOF
+
+       git rev-parse --symbolic-full-name --bisect >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success '--short= truncates to the actual hash length' '
        git rev-parse HEAD >expect &&
        git rev-parse --short=100 HEAD >actual &&