Skip to content

Commit

Permalink
Fix repository creation error handling
Browse files Browse the repository at this point in the history
Now we also catch GitError as introduced in 0.25.1
See also: libgit2/pygit2#645 and libgit2/pygit2#698
  • Loading branch information
white-gecko committed Jun 26, 2018
1 parent 1961e1e commit ae90acb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion quit/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import logging

from _pygit2 import GitError
from os.path import expanduser, join
from quit.exceptions import RepositoryNotFound, RevisionNotFound, NodeNotFound, RemoteNotFound
from quit.exceptions import QuitMergeConflict, QuitGitRefNotFound, QuitGitRepoError
Expand Down Expand Up @@ -45,7 +46,7 @@ def __init__(self, path, origin=None, create=False, garbageCollection=False):

try:
self._repository = pygit2.Repository(path)
except KeyError:
except (KeyError, GitError):
if not create:
raise RepositoryNotFound(
'Repository "%s" does not exist' % path)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ def createcommit(self):
def testInitNotExistingsRepo(self):
dir = TemporaryDirectory()

repo = quit.git.Repository(self.dir.name)
repo = quit.git.Repository(dir.name, create=True)
self.assertFalse(repo.is_bare)
self.assertEqual(len(repo.revisions()), 0)

dir.cleanup()

def testInitEmptyRepo(self):
self.addfile()
repo = quit.git.Repository(self.dir.name)
repo = quit.git.Repository(self.dir.name, create=True)
self.assertFalse(repo.is_bare)
self.assertEqual(len(repo.revisions()), 0)

Expand Down

0 comments on commit ae90acb

Please sign in to comment.