After the recent series of patches ^{tag} and ^{blob} now work to get
just the tags and blobs, but ^{tree} will still list any
tree-ish (commits, tags and trees).
The previous behavior was added in ed1ca6025f ("peel_onion:
disambiguate to favor tree-ish when we know we want a tree-ish",
2013-03-31). I may have missed some special-case but this makes more
sense to me.
Now "$sha1:" can be used as before to mean treeish
$ git rev-parse e8f2:
error: short SHA1 e8f2 is ambiguous
hint: The candidates are:
hint: e8f2650052 tag v2.17.0
hint: e8f21caf94 commit 2013-06-24 - bash prompt: print unique detached
HEAD abbreviated object name
hint: e8f26250fa commit 2017-02-03 - Merge pull request #996 from
jeffhostetler/jeffhostetler/register_rename_src
hint: e8f2bc0c06 commit 2015-05-10 - Documentation: note behavior for
multiple remote.url entries
hint: e8f2093055 tree
hint: e8f25a3a50 tree
hint: e8f28d537c tree
hint: e8f2cf6ec0 tree
[...]
But ^{tree} shows just the trees, but would previously be equivalent
to the above:
$ git rev-parse e8f2^{tree}
error: short SHA1 e8f2 is ambiguous
hint: The candidates are:
hint: e8f2093055 tree
hint: e8f25a3a50 tree
hint: e8f28d537c tree
hint: e8f2cf6ec0 tree
[...]
Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
---
sha1-name.c | 2 +-
t/t1512-rev-parse-disambiguation.sh | 18 ++++++++++++++----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/sha1-name.c b/sha1-name.c
index 023f9471a8..b61c0558d9 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -970,7 +970,7 @@ static int peel_onion(const char *name, int len, struct
object_id *oid,
else if (expected_type == OBJ_TAG)
lookup_flags |= GET_OID_TAG;
else if (expected_type == OBJ_TREE)
- lookup_flags |= GET_OID_TREEISH;
+ lookup_flags |= GET_OID_TREE;
else if (expected_type == OBJ_BLOB)
lookup_flags |= GET_OID_BLOB;
diff --git a/t/t1512-rev-parse-disambiguation.sh
b/t/t1512-rev-parse-disambiguation.sh
index 9ce9cc3bc3..81076449a2 100755
--- a/t/t1512-rev-parse-disambiguation.sh
+++ b/t/t1512-rev-parse-disambiguation.sh
@@ -159,9 +159,13 @@ test_expect_failure 'two semi-ambiguous commit-ish' '
git log 0000000000...
'
-test_expect_failure 'three semi-ambiguous tree-ish' '
+test_expect_success 'three semi-ambiguous tree-ish' '
# Likewise for tree-ish. HEAD, v1.0.0 and HEAD^{tree} share
# the prefix but peeling them to tree yields the same thing
+ test_must_fail git rev-parse --verify 0000000000: &&
+
+ # For ^{tree} we can disambiguate because HEAD and v1.0.0 will
+ # be excluded.
git rev-parse --verify 0000000000^{tree}
'
@@ -267,8 +271,12 @@ test_expect_success 'ambiguous commit-ish' '
# There are three objects with this prefix: a blob, a tree, and a tag. We know
# the blob will not pass as a treeish, but the tree and tag should (and thus
# cause an error).
-test_expect_success 'ambiguous tags peel to treeish' '
- test_must_fail git rev-parse 0000000000f^{tree}
+test_expect_success 'ambiguous tags peel to treeish or tree' '
+ test_must_fail git rev-parse 0000000000f: &&
+ git rev-parse 0000000000f^{tree} >stdout &&
+ test_line_count = 1 stdout &&
+ grep -q ^0000000000fd8bcc56 stdout
+
'
test_expect_success 'rev-parse --disambiguate' '
@@ -365,7 +373,9 @@ test_expect_success 'core.disambiguate config can prefer
types' '
test_expect_success 'core.disambiguate does not override context' '
# treeish ambiguous between tag and tree
test_must_fail \
- git -c core.disambiguate=committish rev-parse $sha1^{tree}
+ git -c core.disambiguate=committish rev-parse $sha1: &&
+ # tree not ambiguous between tag and tree
+ git -c core.disambiguate=committish rev-parse $sha1^{tree}
'
test_expect_success C_LOCALE_OUTPUT 'ambiguous commits are printed by type
first, then hash order' '
--
2.17.0.290.gded63e768a