Fix coverage and path to repo dir

This commit is contained in:
Simon Segerblom Rex 2024-03-14 13:59:50 +01:00
parent 7923236bb6
commit 42fe699ef4
2 changed files with 11 additions and 2 deletions

View file

@ -75,9 +75,10 @@ def _install_hook_script(
git_dir = git_dir if git_dir is not None else git.get_git_common_dir()
# If the hooks directory links to a directory outside the
# git repo we shouldn't try to mess with it
repo_dir = os.path.dirname(os.path.realpath(git_dir))
if os.path.commonpath(
[os.path.realpath(git_dir), os.path.realpath(hook_path)],
) != os.path.realpath(git_dir):
[repo_dir, os.path.realpath(hook_path)]
) != repo_dir:
logger.error(
'Cowardly refusing to install hook script to a directory '
'outside of the git repo.\n'

View file

@ -109,6 +109,14 @@ def test_install_hooks_dead_symlink(in_git_dir, store):
assert hook.exists()
def test_install_hooks_symlink_inside_git_repo(in_git_dir, store):
hooks_dir = in_git_dir.join('.git/hooks')
os.symlink(in_git_dir.join('hooks').ensure_dir().strpath, hooks_dir.strpath)
hook = hooks_dir.join('pre-commit')
assert install(C.CONFIG_FILE, store, hook_types=['pre-commit']) == 0
assert hook.exists()
def test_install_hooks_symlink_outisde_git_repo(in_git_dir, store):
hooks_dir = in_git_dir.join('.git/hooks')
os.symlink(in_git_dir.join('../hooks').ensure_dir().strpath, hooks_dir.strpath)