Skip to content

Commit

Permalink
Merge pull request #1996 from flichtenheld/git-rev-parse
Browse files Browse the repository at this point in the history
Repo.rev_parse: Handle <tag>^{commit} correctly
  • Loading branch information
Byron authored Jan 10, 2025
2 parents 340044b + e4f1aa7 commit 333786c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion git/repo/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,13 @@ def rev_parse(repo: "Repo", rev: str) -> AnyGitObject:

# Handle type.
if output_type == "commit":
pass # Default.
obj = cast("TagObject", obj)
if obj and obj.type == "tag":
obj = deref_tag(obj)
else:
# Cannot do anything for non-tags.
pass
# END handle tag
elif output_type == "tree":
try:
obj = cast(AnyGitObject, obj)
Expand Down
4 changes: 2 additions & 2 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,9 +1064,9 @@ def test_rev_parse(self):
# TODO: Dereference tag into a blob 0.1.7^{blob} - quite a special one.
# Needs a tag which points to a blob.

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

Expand Down

0 comments on commit 333786c

Please sign in to comment.