mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
fix execution in worktrees in subdirectories of bare repositories
This commit is contained in:
parent
7727f8777a
commit
f75fc6b2a8
3 changed files with 21 additions and 6 deletions
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue