Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45a0f90

Browse files
authored
Merge pull request #718 from pre-commit/core_hookspath
Refuse to install with core.hooksPath set
2 parents ac3a37d + f679983 commit 45a0f90

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

pre_commit/commands/install_uninstall.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
from __future__ import unicode_literals
33

44
import io
5+
import logging
56
import os.path
67
import sys
78

89
from pre_commit import output
10+
from pre_commit.util import cmd_output
911
from pre_commit.util import make_executable
1012
from pre_commit.util import mkdirp
1113
from pre_commit.util import resource_filename
1214

1315

16+
logger = logging.getLogger(__name__)
17+
1418
# This is used to identify the hook file we install
1519
PRIOR_HASHES = (
1620
'4d9958c90bc262f47553e2c073f14cfe',
@@ -36,6 +40,13 @@ def install(
3640
skip_on_missing_conf=False,
3741
):
3842
"""Install the pre-commit hooks."""
43+
if cmd_output('git', 'config', 'core.hooksPath', retcode=None)[1].strip():
44+
logger.error(
45+
'Cowardly refusing to install hooks with `core.hooksPath` set.\n'
46+
'hint: `git config --unset-all core.hooksPath`',
47+
)
48+
return 1
49+
3950
hook_path = runner.get_hook_path(hook_type)
4051
legacy_path = hook_path + '.legacy'
4152

tests/commands/install_uninstall_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def test_install_hooks_directory_not_present(tempdir_factory):
6666
assert os.path.exists(runner.pre_commit_path)
6767

6868

69+
def test_install_refuses_core_hookspath(tempdir_factory):
70+
path = git_dir(tempdir_factory)
71+
with cwd(path):
72+
cmd_output('git', 'config', '--local', 'core.hooksPath', 'hooks')
73+
runner = Runner(path, C.CONFIG_FILE)
74+
assert install(runner)
75+
76+
6977
@xfailif_no_symlink
7078
def test_install_hooks_dead_symlink(
7179
tempdir_factory,

0 commit comments

Comments
 (0)