Skip to content

Commit 5d5def2

Browse files
peffgitster
authored andcommitted
get_short_sha1: parse tags when looking for treeish
The treeish disambiguation function tries to peel tags, but it does so by calling: deref_tag(lookup_object(sha1), ...); This will only work if we have previously looked at the tag and created a "struct tag" for it. Since parsing revision arguments typically happens before anything else, this is usually not the case, and we would fail to peel the tag (we are lucky that deref_tag() gracefully handles the NULL and does not segfault). Instead, we can use parse_object(). Note that this is the same fix done by 94d75d1 (get_short_sha1(): correctly disambiguate type-limited abbreviation, 2013-07-01), but that commit fixed only the committish disambiguator, and left the bug in the treeish one. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a10fea commit 5d5def2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

sha1_name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static int disambiguate_treeish_only(const unsigned char *sha1, void *cb_data_un
269269
return 0;
270270

271271
/* We need to do this the hard way... */
272-
obj = deref_tag(lookup_object(sha1), NULL, 0);
272+
obj = deref_tag(parse_object(sha1), NULL, 0);
273273
if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
274274
return 1;
275275
return 0;

t/t1512-rev-parse-disambiguation.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ test_expect_success 'ambiguous commit-ish' '
264264
test_must_fail git log 000000000...
265265
'
266266

267+
# There are three objects with this prefix: a blob, a tree, and a tag. We know
268+
# the blob will not pass as a treeish, but the tree and tag should (and thus
269+
# cause an error).
270+
test_expect_success 'ambiguous tags peel to treeish' '
271+
test_must_fail git rev-parse 0000000000f^{tree}
272+
'
273+
267274
test_expect_success 'rev-parse --disambiguate' '
268275
# The test creates 16 objects that share the prefix and two
269276
# commits created by commit-tree in earlier tests share a

0 commit comments

Comments
 (0)