mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Refuse to install with core.hooksPath set
This commit is contained in:
parent
ac3a37d1a0
commit
f679983012
2 changed files with 19 additions and 0 deletions
|
|
@ -2,15 +2,19 @@ from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import io
|
import io
|
||||||
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pre_commit import output
|
from pre_commit import output
|
||||||
|
from pre_commit.util import cmd_output
|
||||||
from pre_commit.util import make_executable
|
from pre_commit.util import make_executable
|
||||||
from pre_commit.util import mkdirp
|
from pre_commit.util import mkdirp
|
||||||
from pre_commit.util import resource_filename
|
from pre_commit.util import resource_filename
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# This is used to identify the hook file we install
|
# This is used to identify the hook file we install
|
||||||
PRIOR_HASHES = (
|
PRIOR_HASHES = (
|
||||||
'4d9958c90bc262f47553e2c073f14cfe',
|
'4d9958c90bc262f47553e2c073f14cfe',
|
||||||
|
|
@ -36,6 +40,13 @@ def install(
|
||||||
skip_on_missing_conf=False,
|
skip_on_missing_conf=False,
|
||||||
):
|
):
|
||||||
"""Install the pre-commit hooks."""
|
"""Install the pre-commit hooks."""
|
||||||
|
if cmd_output('git', 'config', 'core.hooksPath', retcode=None)[1].strip():
|
||||||
|
logger.error(
|
||||||
|
'Cowardly refusing to install hooks with `core.hooksPath` set.\n'
|
||||||
|
'hint: `git config --unset-all core.hooksPath`',
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
hook_path = runner.get_hook_path(hook_type)
|
hook_path = runner.get_hook_path(hook_type)
|
||||||
legacy_path = hook_path + '.legacy'
|
legacy_path = hook_path + '.legacy'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,14 @@ def test_install_hooks_directory_not_present(tempdir_factory):
|
||||||
assert os.path.exists(runner.pre_commit_path)
|
assert os.path.exists(runner.pre_commit_path)
|
||||||
|
|
||||||
|
|
||||||
|
def test_install_refuses_core_hookspath(tempdir_factory):
|
||||||
|
path = git_dir(tempdir_factory)
|
||||||
|
with cwd(path):
|
||||||
|
cmd_output('git', 'config', '--local', 'core.hooksPath', 'hooks')
|
||||||
|
runner = Runner(path, C.CONFIG_FILE)
|
||||||
|
assert install(runner)
|
||||||
|
|
||||||
|
|
||||||
@xfailif_no_symlink
|
@xfailif_no_symlink
|
||||||
def test_install_hooks_dead_symlink(
|
def test_install_hooks_dead_symlink(
|
||||||
tempdir_factory,
|
tempdir_factory,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue