Skip to content

Commit

Permalink
Add test_get_root_not_in_working_dir()
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Feb 18, 2022
1 parent 9a309ac commit 60bc363
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pre_commit/git.py
Expand Up @@ -88,8 +88,7 @@ def get_git_common_dir(git_root: str = '.') -> str:
git_common_dir = out.strip()
if git_common_dir != opt:
return os.path.normpath(os.path.join(git_root, git_common_dir))
else:
# pragma: no branch (git < 2.5)
else: # pragma: no cover (git < 2.5)
return get_git_dir(git_root)


Expand Down
7 changes: 7 additions & 0 deletions tests/git_test.py
Expand Up @@ -28,6 +28,13 @@ def test_get_root_in_git_sub_dir(in_git_dir):
assert os.path.normcase(git.get_root()) == expected


def test_get_root_not_in_working_dir(in_git_dir):
expected = os.path.normcase(in_git_dir.strpath)
with pytest.raises(FatalError):
with in_git_dir.join('..').ensure_dir().as_cwd():
assert os.path.normcase(git.get_root()) == expected


def test_in_exactly_dot_git(in_git_dir):
with in_git_dir.join('.git').as_cwd(), pytest.raises(FatalError):
git.get_root()
Expand Down

0 comments on commit 60bc363

Please sign in to comment.