Skip to content

Commit 6ee9e13

Browse files
committed
prevent infinite recursion of post-checkout on clone
1 parent 2f25085 commit 6ee9e13

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pre_commit/git.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def init_repo(path: str, remote: str) -> None:
158158
remote = os.path.abspath(remote)
159159

160160
env = no_git_env()
161-
cmd_output_b('git', 'init', path, env=env)
161+
# avoid the user's template so that hooks do not recurse
162+
cmd_output_b('git', 'init', '--template=', path, env=env)
162163
cmd_output_b('git', 'remote', 'add', 'origin', remote, cwd=path, env=env)
163164

164165

tests/git_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,8 @@ def test_no_git_env():
186186
'GIT_SSH': '/usr/bin/ssh',
187187
'GIT_SSH_COMMAND': 'ssh -o',
188188
}
189+
190+
191+
def test_init_repo_no_hooks(tmpdir):
192+
git.init_repo(str(tmpdir), remote='dne')
193+
assert not tmpdir.join('.git/hooks').exists()

0 commit comments

Comments
 (0)