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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 26, 2016 at 07:59 UTC 5d5def2aa56dc9b6d4eccfb333fd08aa713733e7
2 files changed +8 -1
sha1_name.c
+1 -1
@@ -269,7 +269,7 @@ static int disambiguate_treeish_only(const unsigned char *sha1, void *cb_data_un
269 return 0;
270
271 /* 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);
273 if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
274 return 1;
275 return 0;
t/t1512-rev-parse-disambiguation.sh
+7
@@ -264,6 +264,13 @@ test_expect_success 'ambiguous commit-ish' '
264 test_must_fail git log 000000000...
265 '
266
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 +
274 test_expect_success 'rev-parse --disambiguate' '
275 # The test creates 16 objects that share the prefix and two
276 # commits created by commit-tree in earlier tests share a