From d503f07d3de94a6518632ec739ef23c6d12d0a9e Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 20 Apr 2020 10:04:30 -0700 Subject: [PATCH] Use a unique origin name to avoid poorly configured git --- pre_commit/git.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pre_commit/git.py b/pre_commit/git.py index 7e757f24..b23894af 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -158,8 +158,15 @@ 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) - cmd_output_b('git', 'remote', 'add', 'origin', remote, cwd=path, env=env) + + def _git(*cmd: str) -> None: + cmd_output_b('git', *cmd, cwd=path, env=env) + + os.makedirs(path, exist_ok=True) + _git('init', '.') + origin = '_pre-commit-origin' + _git('remote', 'add', origin, remote) + _git('remote', 'rename', origin, 'origin') def commit(repo: str = '.') -> None: