Skip to content

Commit

Permalink
prevent infinite recursion of post-checkout on clone
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jun 9, 2020
1 parent f32bc64 commit 3bf2ba0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pre_commit/git.py
Expand Up @@ -158,7 +158,8 @@ def init_repo(path: str, remote: str) -> None:
remote = os.path.abspath(remote)

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


Expand Down
5 changes: 5 additions & 0 deletions tests/git_test.py
Expand Up @@ -186,3 +186,8 @@ def test_no_git_env():
'GIT_SSH': '/usr/bin/ssh',
'GIT_SSH_COMMAND': 'ssh -o',
}


def test_init_repo_no_hooks(tmpdir):
git.init_repo(tmpdir, remote='https://github.com/asottile/pyupgrade')
assert not tmpdir.join('.git/hooks').exists()

0 comments on commit 3bf2ba0

Please sign in to comment.