summaryrefslogtreecommitdiffstats
path: root/tests/git_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/git_test.py')
-rw-r--r--tests/git_test.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/git_test.py b/tests/git_test.py
index fafd4a6..69fd206 100644
--- a/tests/git_test.py
+++ b/tests/git_test.py
@@ -3,6 +3,7 @@ import os.path
import pytest
from pre_commit import git
+from pre_commit.error_handler import FatalError
from pre_commit.util import cmd_output
from testing.util import git_commit
@@ -18,6 +19,25 @@ def test_get_root_deeper(in_git_dir):
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()
+
+
+def test_get_root_bare_worktree(tmpdir):
+ src = tmpdir.join('src').ensure_dir()
+ cmd_output('git', 'init', str(src))
+ git_commit(cwd=str(src))
+
+ bare = tmpdir.join('bare.git').ensure_dir()
+ cmd_output('git', 'clone', '--bare', str(src), str(bare))
+
+ cmd_output('git', 'worktree', 'add', 'foo', 'HEAD', cwd=bare)
+
+ with bare.join('foo').as_cwd():
+ assert git.get_root() == os.path.abspath('.')
+
+
def test_get_staged_files_deleted(in_git_dir):
in_git_dir.join('test').ensure()
cmd_output('git', 'add', 'test')