Skip to content

Commit e3d29a8

Browse files
committed
Make git errors throw FatalError
1 parent 74e878d commit e3d29a8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pre_commit/git.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@
77
import re
88
from plumbum import local
99

10+
from pre_commit.errors import FatalError
1011
from pre_commit.util import memoize_by_cwd
1112

1213

1314
logger = logging.getLogger('pre_commit')
1415

1516

16-
@memoize_by_cwd
1717
def get_root():
1818
path = os.getcwd()
1919
while len(path) > 1:
2020
if os.path.exists(os.path.join(path, '.git')):
2121
return path
2222
else:
2323
path = os.path.normpath(os.path.join(path, '../'))
24-
raise AssertionError('called from outside of the gits')
24+
raise FatalError(
25+
'Called from outside of the gits. '
26+
'Please cd to a git repository.'
27+
)
2528

2629

2730
def is_in_merge_conflict():

tests/git_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from plumbum import local
77

88
from pre_commit import git
9+
from pre_commit.errors import FatalError
910
from testing.fixtures import git_dir
1011

1112

@@ -24,6 +25,12 @@ def test_get_root_deeper(tmpdir_factory):
2425
assert git.get_root() == path
2526

2627

28+
def test_get_root_not_git_dir(tmpdir_factory):
29+
with local.cwd(tmpdir_factory.get()):
30+
with pytest.raises(FatalError):
31+
git.get_root()
32+
33+
2734
def test_is_not_in_merge_conflict(tmpdir_factory):
2835
path = git_dir(tmpdir_factory)
2936
with local.cwd(path):

0 commit comments

Comments
 (0)