-
Notifications
You must be signed in to change notification settings - Fork 15
Description
How to reproduce it:
$ mkdir scmtest
$ cd scmtest
# this is correct
$ python3 -c "from scmrepo.git import Git; Git('.').pygit2.resolve_rev('HEAD~')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/gao/anaconda3/envs/dvc/lib/python3.8/site-packages/scmrepo/git/backend/pygit2.py", line 271, in resolve_rev
raise RevError(f"unknown Git revision '{rev}'")
scmrepo.exceptions.RevError: unknown Git revision 'HEAD~'
# add some remote
$ git remote add origin someremote
# do not wrap the exception properly from `pygit2`
$ python3 -c "from scmrepo.git import Git; Git('.').pygit2.resolve_rev('HEAD~')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/gao/anaconda3/envs/dvc/lib/python3.8/site-packages/scmrepo/git/backend/pygit2.py", line 263, in resolve_rev
shas = {
File "/Users/gao/anaconda3/envs/dvc/lib/python3.8/site-packages/scmrepo/git/backend/pygit2.py", line 264, in <setcomp>
self.get_ref(f"refs/remotes/{remote.name}/{rev}")
File "/Users/gao/anaconda3/envs/dvc/lib/python3.8/site-packages/scmrepo/git/backend/pygit2.py", line 322, in get_ref
ref = self.repo.references.get(name)
File "/Users/gao/anaconda3/envs/dvc/lib/python3.8/site-packages/pygit2/repository.py", line 1440, in get
return self[key]
File "/Users/gao/anaconda3/envs/dvc/lib/python3.8/site-packages/pygit2/repository.py", line 1436, in __getitem__
return self._repository.lookup_reference(name)
_pygit2.InvalidSpecError: refs/remotes/origin/HEAD~: the given reference name 'refs/remotes/origin/HEAD~' is not valid
# gitpython works correctly
python3 -c "from scmrepo.git import Git; Git('.').gitpython.resolve_rev('HEAD~')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/gao/anaconda3/envs/dvc/lib/python3.8/site-packages/scmrepo/git/backend/gitpython.py", line 352, in resolve_rev
raise RevError(f"unknown Git revision '{rev}'")
scmrepo.exceptions.RevError: unknown Git revision 'HEAD~'
For now, the default backend for resolve_rev is pygit2, and it causes some problems in treeverse/dvc#7204 (comment). To solve this, we have two choices:
- wrap the
_pygit2.InvalidSpecErrorfrom inpygit2backend. - use
gitpythonbackend instead.
Metadata
Metadata
Assignees
Labels
No labels