Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError when referencing from packed-refs #910

Closed
aslakrin opened this issue May 23, 2019 · 0 comments
Closed

ValueError when referencing from packed-refs #910

aslakrin opened this issue May 23, 2019 · 0 comments
Labels

Comments

@aslakrin
Copy link

Using pygit2-0.28.1, I have an issue when using for example repo.branches.with_commit() and one of the branches is in the packed-refs file.

Reproduce with tests/submodulerepo.tar:

subrepo = pygit2.Repository(r"path\pygit2\test\data\submodulerepo")
# SHA1 for refs/remotes/origin/master from submodulerepo/.git/packed-refs
branches = subrepo.branches.with_commit('215fc695515c4093e2beffb21225ce6e1b3d55bc')
list(branches.remote) # This raises ValueError

You'll get:

  File "<input>", line 1, in <module>
  File "path\lib\site-packages\pygit2\repository.py", line 1181, in __iter__
    if self._commit is None or self.get(branch_name) is not None:
  File "path\lib\site-packages\pygit2\repository.py", line 1175, in get
    return self[key]
  File "path\lib\site-packages\pygit2\repository.py", line 1168, in __getitem__
    if branch is None or not self._valid(branch):
  File "path\lib\site-packages\pygit2\repository.py", line 1197, in _valid
    self._repository.descendant_of(branch.target, self._commit))
ValueError: refs/remotes/origin/master

I'm not 100% sure that it's related to packed-ref, but I tried reproducing when the ref actually exists as a file and didn't get the same issue.

In my ignorance I came up with a workaround,

# pygit2/repository.py :: L1190
    def _valid(self, branch):
        try:
            target = self._repository.expand_id(branch.target)
        except ValueError:
            target = self._repository.expand_id(self._repository.lookup_reference(branch.target).target)

        return (self._commit is None or target == self._commit or  # target was branch.target
                self._repository.descendant_of(target, self._commit))  # target was branch.target
@jdavid jdavid added the bug label May 25, 2019
@jdavid jdavid closed this as completed in 28e2e1a May 25, 2019
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 11, 2019
0.28.2 (2019-05-26)
-------------------------

- Fix crash in reflog iteration
  `#901 <https://github.com/libgit2/pygit2/issues/901>`_

- Support symbolic references in ``branches.with_commit(..)``
  `#910 <https://github.com/libgit2/pygit2/issues/910>`_

- Documentation updates
  `#909 <https://github.com/libgit2/pygit2/pull/909>`_

- Test updates
  `#911 <https://github.com/libgit2/pygit2/pull/911>`_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants