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.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/git_test.py b/tests/git_test.py
index bcb3fd1..b9f524a 100644
--- a/tests/git_test.py
+++ b/tests/git_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import os.path
import pytest
@@ -19,6 +21,20 @@ def test_get_root_deeper(in_git_dir):
assert os.path.normcase(git.get_root()) == expected
+def test_get_root_in_git_sub_dir(in_git_dir):
+ expected = os.path.normcase(in_git_dir.strpath)
+ with pytest.raises(FatalError):
+ with in_git_dir.join('.git/objects').ensure_dir().as_cwd():
+ 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()
@@ -38,6 +54,22 @@ def test_get_root_bare_worktree(tmpdir):
assert git.get_root() == os.path.abspath('.')
+def test_get_git_dir(tmpdir):
+ """Regression test for #1972"""
+ src = tmpdir.join('src').ensure_dir()
+ cmd_output('git', 'init', str(src))
+ git_commit(cwd=str(src))
+
+ worktree = tmpdir.join('worktree').ensure_dir()
+ cmd_output('git', 'worktree', 'add', '../worktree', cwd=src)
+
+ with worktree.as_cwd():
+ assert git.get_git_dir() == src.ensure_dir(
+ '.git/worktrees/worktree',
+ )
+ assert git.get_git_common_dir() == src.ensure_dir('.git')
+
+
def test_get_root_worktree_in_git(tmpdir):
src = tmpdir.join('src').ensure_dir()
cmd_output('git', 'init', str(src))