Skip to content

Commit 1ab4f77

Browse files
committed
Handle pygit2.discover_repository() returning None.
A breaking change was made in pygit2 0.27.1: it now returns None instead of raising a KeyError if the specified path is not in a Git repository.
1 parent 5f5ae31 commit 1ab4f77

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

gitless/core.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class PathIsDirectoryError(ValueError): pass
5858
GL_STATUS_IGNORED = 3
5959

6060

61+
def error_on_none(path):
62+
"""Raise a KeyError if the ```path``` argument is None."""
63+
if path is None:
64+
raise KeyError('path')
65+
return path
66+
67+
6168
def init_repository(url=None):
6269
"""Creates a new Gitless's repository in the cwd.
6370
@@ -67,7 +74,7 @@ def init_repository(url=None):
6774
"""
6875
cwd = os.getcwd()
6976
try:
70-
pygit2.discover_repository(cwd)
77+
error_on_none(pygit2.discover_repository(cwd))
7178
raise GlError('You are already in a Gitless repository')
7279
except KeyError: # Expected
7380
if not url:
@@ -108,7 +115,7 @@ class Repository(object):
108115
def __init__(self):
109116
"""Create a Repository out of the current working repository."""
110117
try:
111-
path = pygit2.discover_repository(os.getcwd())
118+
path = error_on_none(pygit2.discover_repository(os.getcwd()))
112119
except KeyError:
113120
raise NotInRepoError('You are not in a Gitless\'s repository')
114121

0 commit comments

Comments
 (0)