mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fix coverage and path to repo dir
This commit is contained in:
parent
7923236bb6
commit
42fe699ef4
2 changed files with 11 additions and 2 deletions
|
|
@ -75,9 +75,10 @@ def _install_hook_script(
|
||||||
git_dir = git_dir if git_dir is not None else git.get_git_common_dir()
|
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
|
# If the hooks directory links to a directory outside the
|
||||||
# git repo we shouldn't try to mess with it
|
# git repo we shouldn't try to mess with it
|
||||||
|
repo_dir = os.path.dirname(os.path.realpath(git_dir))
|
||||||
if os.path.commonpath(
|
if os.path.commonpath(
|
||||||
[os.path.realpath(git_dir), os.path.realpath(hook_path)],
|
[repo_dir, os.path.realpath(hook_path)]
|
||||||
) != os.path.realpath(git_dir):
|
) != repo_dir:
|
||||||
logger.error(
|
logger.error(
|
||||||
'Cowardly refusing to install hook script to a directory '
|
'Cowardly refusing to install hook script to a directory '
|
||||||
'outside of the git repo.\n'
|
'outside of the git repo.\n'
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,14 @@ def test_install_hooks_dead_symlink(in_git_dir, store):
|
||||||
assert hook.exists()
|
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):
|
def test_install_hooks_symlink_outisde_git_repo(in_git_dir, store):
|
||||||
hooks_dir = in_git_dir.join('.git/hooks')
|
hooks_dir = in_git_dir.join('.git/hooks')
|
||||||
os.symlink(in_git_dir.join('../hooks').ensure_dir().strpath, hooks_dir.strpath)
|
os.symlink(in_git_dir.join('../hooks').ensure_dir().strpath, hooks_dir.strpath)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue