pygit2 icon indicating copy to clipboard operation
pygit2 copied to clipboard

Can not walk over a repository with detached HEAD

Open hasanatkazmi opened this issue 5 years ago • 3 comments

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)'

hasanatkazmi avatar Mar 27 '20 20:03 hasanatkazmi

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

yoichi avatar Oct 24 '21 00:10 yoichi

Currently, libgit2 doesn't support shallow repositories.

There is an issue about it: https://github.com/libgit2/libgit2/issues/3058

yoichi avatar Oct 24 '21 14:10 yoichi

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?

red8888 avatar Jan 18 '23 22:01 red8888