Can not walk over a repository with detached HEAD
Subject says it all. Here is the steps to reproduce it:
% git clone --depth 1 <URL>
% git fetch --depth 1 origin <revision hash>
% git checkout FETCH_HEAD
>>> from pygit2 import Repository
>>> repo = Repositoy(<Path to a repo>)
>>> for commit in repo.walk(revision):
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'object not found - no match for id (0c946642a3608917c3c543355de6426d5b69583b)'
The error is not caused by the detached HEAD, it is caused by the parent commit objects are not fetched (shallow repository).
I think this is a libgit2 issue, git_revwalk_next() returns GIT_ENOTFOUND at prepare_walk(), before returning existing commit objects https://github.com/libgit2/libgit2/blob/9b04a3076d419279ac43f165be89a9893f9f0670/src/revwalk.c#L414
Currently, libgit2 doesn't support shallow repositories.
There is an issue about it: https://github.com/libgit2/libgit2/issues/3058
There is a link to a PR in that issue that adds support: https://github.com/libgit2/libgit2/pull/6396
Been in review for a few months.
@yoichi after thats merged will this just work with pygit2 or will pygit2 also require code changes?