pygit2 icon indicating copy to clipboard operation
pygit2 copied to clipboard

ValueError `repo.branches.get('branch_no_exist/')` trailing slashes in branch names

Open Richard-Mathie opened this issue 7 years ago • 2 comments

if i have a repo and call

>> 'branch_no_exist' in repo.branches
False

as expected, but

>> 'branch_no_exist/' in repo.branches
Traceback (most recent call last):

  pygit2/repository.py", line 1156, in get
    return self[key]
 pygit2/repository.py", line 1144, in __getitem__
    branch = self._repository.lookup_branch(name, GIT_BRANCH_LOCAL)
ValueError: cannot locate local branch 'branch_no_exist/'

Given branch names Shouldn't end in a slash, but the error is not complaining about this.

should repository.lookup_branch be returning None in this case?

Richard-Mathie avatar Oct 25 '18 10:10 Richard-Mathie

This looks related to issue #828

If branch names are not allowed to have slashes then it should fail with an informative error, probably InvalidSpecError since PR #829 ; did you test with latest version of the master branch?

Definitive name of the exception may change before the next release, see issue #830

jdavid avatar Oct 25 '18 11:10 jdavid

To get the expected result (without throwing exception), create list as:

>>> 'branch_no_exist/' in list(repo.branches)
False

yoichi avatar Oct 23 '21 12:10 yoichi