pygit2 icon indicating copy to clipboard operation
pygit2 copied to clipboard

Repository.resolve_refish can return a Tag, violates docstring and typehint

Open linyaa-kiwi opened this issue 6 months ago • 0 comments

The typing hint and docstring of Repository.resolve_refish says it returns a Commit object. Actually, it will return a Tag object if given a tag's hex oid. Is this the expected behavior.

For example, in the Linux kernel:

assert pygit2.__version__ == "1.18.0"

# OID of `v6.12.1^{tag}` and v6.12.1^{commit}` in Linux kernel.                 
tag_oid = Oid(hex="a554dea023a451ad985c071f8aae6415f0e274df")   
commit_oid = Oid(hex="d390303b28dabbb91b2d32016a4f72da478733b9")
                                                                
# As documented, symbolic refs resolve to a commit object.
# But the ref target differs from the returned object. Is this the desired behavior?
obj, ref = repo.resolve_refish("v6.12.1")             
assert isinstance(obj, Commit)                                  
assert ref.target != obj.id
assert ref.target == tag_oid                               

# Contrary to the docstring and typing hint, this returns a Tag object.                                                                
obj, ref = repo.resolve_refish(str(tag_oid))                    
assert isinstance(obj, Tag)                                     
assert ref is None

linyaa-kiwi avatar Aug 23 '25 00:08 linyaa-kiwi