Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

InvalidSpecError for `repo.checkout("rev")` when `git checkout rev` works fine

Open
#1,217 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
git, python
Domain
tooling

Research direction

Start at pygit2/repository.py around the checkout implementation and reproduce the provided commit-hash example. Compare how the Python binding resolves the argument with the behavior expected from git checkout; done means the shown commit hash is accepted by repo.checkout without InvalidSpecError.

Written by the indexing model from the issue text.

Description

To reproduce:

git clone https://src.fedoraproject.org/rpms/python-pymongo.git
cd python-pymongo
python3
>>> import pygit2
>>> pyrepo = pygit2.Repository("./")
>>> pyrepo.checkout("a3432e746082d0c96811cbf87aa7ae8e7fe62bc8")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.11/site-packages/pygit2/repository.py", line 420, in checkout
    reference = self.lookup_reference(refname)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_pygit2.InvalidSpecError: a3432e746082d0c96811cbf87aa7ae8e7fe62bc8: the given reference name 'a3432e746082d0c96811cbf87aa7ae8e7fe62bc8' is not valid
>>> (ctrl-d)
[adamw@xps13a python-pymongo (rawhide)]$ git checkout a3432e746082d0c96811cbf87aa7ae8e7fe62bc8
Note: switching to 'a3432e746082d0c96811cbf87aa7ae8e7fe62bc8'.
[...]
HEAD is now at a3432e7 Update to 3.4.0 (#1400227).

so, checkout of that commit works fine with git checkout but not pygit2 checkout. I've no idea why not. Not sure if this is a pygit2 or libgit2 issue.

Dominant language
Python
Stars
1.7k
Forks
408
Avg merge
2d 57m
Merged PRs (30d)
7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from libgit2/pygit2

All issues in libgit2/pygit2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.