Skip to content

Commit 15b6bba

Browse files
committed
fix(tag): improve tag resolution handling
The handling is similar, but the error message makes clear what is happening, and what can be done to handle such a case. Related to gitpython-developers#561
1 parent c823d48 commit 15b6bba

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

git/refs/tag.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ class TagReference(Reference):
2222

2323
@property
2424
def commit(self):
25-
""":return: Commit object the tag ref points to"""
25+
""":return: Commit object the tag ref points to
26+
27+
:raise ValueError: if the tag points to a tree or blob"""
2628
obj = self.object
2729
while obj.type != 'commit':
2830
if obj.type == "tag":
2931
# it is a tag object which carries the commit as an object - we can point to anything
3032
obj = obj.object
3133
else:
32-
raise ValueError("Tag %s points to a Blob or Tree - have never seen that before" % self)
34+
raise ValueError(("Cannot resolve commit as tag %s points to a %s object - "
35+
+ "use the `.object` property instead to access it") % (self, obj.type))
3336
return obj
3437

3538
@property

0 commit comments

Comments
 (0)