Skip to content

Commit 333786c

Browse files
authored
Merge pull request #1996 from flichtenheld/git-rev-parse
Repo.rev_parse: Handle <tag>^{commit} correctly
2 parents 340044b + e4f1aa7 commit 333786c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

git/repo/fun.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,13 @@ def rev_parse(repo: "Repo", rev: str) -> AnyGitObject:
301301

302302
# Handle type.
303303
if output_type == "commit":
304-
pass # Default.
304+
obj = cast("TagObject", obj)
305+
if obj and obj.type == "tag":
306+
obj = deref_tag(obj)
307+
else:
308+
# Cannot do anything for non-tags.
309+
pass
310+
# END handle tag
305311
elif output_type == "tree":
306312
try:
307313
obj = cast(AnyGitObject, obj)

test/test_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,9 +1064,9 @@ def test_rev_parse(self):
10641064
# TODO: Dereference tag into a blob 0.1.7^{blob} - quite a special one.
10651065
# Needs a tag which points to a blob.
10661066

1067-
# ref^0 returns commit being pointed to, same with ref~0, and ^{}
1067+
# ref^0 returns commit being pointed to, same with ref~0, ^{}, and ^{commit}
10681068
tag = rev_parse("0.1.4")
1069-
for token in ("~0", "^0", "^{}"):
1069+
for token in ("~0", "^0", "^{}", "^{commit}"):
10701070
self.assertEqual(tag.object, rev_parse("0.1.4%s" % token))
10711071
# END handle multiple tokens
10721072

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy