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

Skip to content

Commit 6c2a148

Browse files
authored
Merge pull request #1299 from pre-commit/hookspath_init_templatedir
allow init-templatedir to succeed when core.hooksPath is set
2 parents f74e303 + d56fdca commit 6c2a148

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

pre_commit/commands/install_uninstall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def install(
123123
skip_on_missing_config: bool = False,
124124
git_dir: Optional[str] = None,
125125
) -> int:
126-
if git.has_core_hookpaths_set():
126+
if git_dir is None and git.has_core_hookpaths_set():
127127
logger.error(
128128
'Cowardly refusing to install hooks with `core.hooksPath` set.\n'
129129
'hint: `git config --unset-all core.hooksPath`',

tests/commands/init_templatedir_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,14 @@ def test_init_templatedir_expanduser(tmpdir, tempdir_factory, store, cap_out):
7979
lines = cap_out.get().splitlines()
8080
assert len(lines) == 1
8181
assert lines[0].startswith('pre-commit installed at')
82+
83+
84+
def test_init_templatedir_hookspath_set(tmpdir, tempdir_factory, store):
85+
target = tmpdir.join('tmpl')
86+
tmp_git_dir = git_dir(tempdir_factory)
87+
with cwd(tmp_git_dir):
88+
cmd_output('git', 'config', '--local', 'core.hooksPath', 'hooks')
89+
init_templatedir(
90+
C.CONFIG_FILE, store, target, hook_types=['pre-commit'],
91+
)
92+
assert target.join('hooks/pre-commit').exists()

0 commit comments

Comments
 (0)