Skip to content

Commit 7730f85

Browse files
peffgitster
authored andcommitted
bisect: peel annotated tags to commits
This patch fixes a bug where git-bisect doesn't handle receiving annotated tags as "git bisect good <tag>", etc. It's a regression in 27257bc (bisect--helper: reimplement `bisect_state` & `bisect_head` shell functions in C, 2020-10-15). The original shell code called: sha=$(git rev-parse --verify "$rev^{commit}") || die "$(eval_gettext "Bad rev input: \$rev")" which will peel the input to a commit (or complain if that's not possible). But the C code just calls get_oid(), which will yield the oid of the tag. The fix is to peel to a commit. The error message here is a little non-idiomatic for Git (since it starts with a capital). I've mostly left it, as it matches the other converted messages (like the "Bad rev input" we print when get_oid() fails), though I did add an indication that it was the peeling that was the problem. It might be worth taking a pass through this converted code to modernize some of the error messages. Note also that the test does a bare "grep" (not i18ngrep) on the expected "X is the first bad commit" output message. This matches the rest of the test script. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94f6e3e commit 7730f85

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

builtin/bisect--helper.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,12 +875,19 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, const char **a
875875
*/
876876

877877
for (; argc; argc--, argv++) {
878+
struct commit *commit;
879+
878880
if (get_oid(*argv, &oid)){
879881
error(_("Bad rev input: %s"), *argv);
880882
oid_array_clear(&revs);
881883
return BISECT_FAILED;
882884
}
883-
oid_array_append(&revs, &oid);
885+
886+
commit = lookup_commit_reference(the_repository, &oid);
887+
if (!commit)
888+
die(_("Bad rev input (not a commit): %s"), *argv);
889+
890+
oid_array_append(&revs, &commit->object.oid);
884891
}
885892

886893
if (strbuf_read_file(&buf, git_path_bisect_expected_rev(), 0) < the_hash_algo->hexsz ||

t/t6030-bisect-porcelain.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,4 +936,16 @@ test_expect_success 'git bisect reset cleans bisection state properly' '
936936
test_path_is_missing ".git/BISECT_START"
937937
'
938938

939+
test_expect_success 'bisect handles annotated tags' '
940+
test_commit commit-one &&
941+
git tag -m foo tag-one &&
942+
test_commit commit-two &&
943+
git tag -m foo tag-two &&
944+
git bisect start &&
945+
git bisect good tag-one &&
946+
git bisect bad tag-two >output &&
947+
bad=$(git rev-parse --verify tag-two^{commit}) &&
948+
grep "$bad is the first bad commit" output
949+
'
950+
939951
test_done

0 commit comments

Comments
 (0)