Content-Length: 1870 | pFad | http://github.com/gitpython-developers/GitPython/pull/1996.patch
thub.com
From e4f1aa71dd255583ff19c1bd40410e94da8e15af Mon Sep 17 00:00:00 2001
From: Frank Lichtenheld
Date: Thu, 9 Jan 2025 17:57:51 +0100
Subject: [PATCH] Repo.rev_parse: Handle ^{commit} correctly
This should resolve to commit object.
Fixes: #1995
Signed-off-by: Frank Lichtenheld
---
git/repo/fun.py | 8 +++++++-
test/test_repo.py | 4 ++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/git/repo/fun.py b/git/repo/fun.py
index 182cf82ed..125ba5936 100644
--- a/git/repo/fun.py
+++ b/git/repo/fun.py
@@ -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)
diff --git a/test/test_repo.py b/test/test_repo.py
index e38da5bb6..bfa1bbb78 100644
--- a/test/test_repo.py
+++ b/test/test_repo.py
@@ -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
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/gitpython-developers/GitPython/pull/1996.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy