Skip to content

Commit ca29184

Browse files
Jonas Rebmanngitster
authored andcommitted
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>
1 parent 320598c commit ca29184

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

builtin/rev-parse.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "builtin.h"
1111

1212
#include "abspath.h"
13+
#include "bisect.h"
1314
#include "config.h"
1415
#include "commit.h"
1516
#include "environment.h"
@@ -940,13 +941,23 @@ int cmd_rev_parse(int argc,
940941
continue;
941942
}
942943
if (!strcmp(arg, "--bisect")) {
944+
char *prefix;
945+
char *term_bad = NULL;
946+
char *term_good = NULL;
943947
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;
945951
refs_for_each_ref_ext(get_main_ref_store(the_repository),
946952
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;
948956
refs_for_each_ref_ext(get_main_ref_store(the_repository),
949957
anti_reference, NULL, &opts);
958+
free(prefix);
959+
free(term_good);
960+
free(term_bad);
950961
continue;
951962
}
952963
if (opt_with_value(arg, "--branches", &arg)) {

t/t1500-rev-parse.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,31 @@ test_expect_success 'rev-parse --bisect includes bad, excludes good' '
337337
test_cmp expect actual
338338
'
339339

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+
340365
test_expect_success '--short= truncates to the actual hash length' '
341366
git rev-parse HEAD >expect &&
342367
git rev-parse --short=100 HEAD >actual &&

0 commit comments

Comments
 (0)