Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Repo.rev_parse: Handle <tag>^{commit} correctly #1996

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading