Add guard against the hooks directory being a symbolic link

`pre-commit install` shouldn't mess with directories
residing outside of the git repository.
This commit is contained in:
Simon Segerblom Rex 2024-03-14 11:49:49 +01:00
parent 3bdf9fb91b
commit fd1cfc60bf
2 changed files with 28 additions and 1 deletions

View file

@ -109,6 +109,14 @@ def test_install_hooks_dead_symlink(in_git_dir, store):
assert hook.exists()
def test_install_hooks_symlink_outisde_git_repo(in_git_dir, store):
hook_dir = in_git_dir.join('.git/hooks')
hook_dir.mksymlinkto(in_git_dir.join("../hooks"))
hook = hook_dir.join('pre-commit')
assert install(C.CONFIG_FILE, store, hook_types=['pre-commit']) != 0
assert not hook.exists()
def test_uninstall_does_not_blow_up_when_not_there(in_git_dir):
assert uninstall(C.CONFIG_FILE, hook_types=['pre-commit']) == 0