summaryrefslogtreecommitdiffstats
path: root/tests/git_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-04 18:42:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-04 18:42:30 +0000
commit9d68e4e3da4ce68e28506d926c7de9fd6ffbf6a3 (patch)
treea6d016823a24941dd795d30ba84409db12aa41cb /tests/git_test.py
parentReleasing debian version 2.17.0-1. (diff)
downloadpre-commit-9d68e4e3da4ce68e28506d926c7de9fd6ffbf6a3.tar.xz
pre-commit-9d68e4e3da4ce68e28506d926c7de9fd6ffbf6a3.zip
Merging upstream version 2.18.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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))