pre-commit: [corner case?] pre-commit fails to add origin when there's settings under origin in the user-global config

Basically, if you do

git config --global --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'

it effectively adds

[remote "origin"]
	fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

to ~/.gitconfig.

And then the failure looks like this:

[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.git.
An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'remote', 'add', 'origin', 'https://github.com/pre-commit/pre-commit-hooks.git')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    fatal: remote origin already exists.
    
Check the log at ~/.cache/pre-commit/pre-commit.log

The solution would be to check if the remote exists and maybe instead do

git config --local remote.origin.url 'https://github.com/pre-commit/pre-commit-hooks.git'
git config --local remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
git fetch --all

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

oh then it’s probably fixed already – I’m going to close this then – the complexity to support this weird use case I don’t think is worth it. if it comes up again I’ll reconsider