Repository.resolve_refish can return a Tag, violates docstring and typehint
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 408
- Avg merge
- 2d 57m
- Merged PRs (30d)
- 7
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Repository.resolve_refish entry point and inspect how symbolic references and direct object IDs are resolved. Look for existing tests covering Commit, Tag, and ref targets, then confirm the intended return contract with the maintainers. Done means the documented and typed behavior matches the verified behavior, with regression coverage for the two examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100