`clone.defaultRemoteName` in `.gitconfig` causes remote configurations to fail
spdiswal opened this issue ยท 2 comments
spdiswal commented
๐ง Summary
When the global .gitconfig
file defines clone.defaultRemoteName
, Lefthook fails on lefthook install
when it attempts to sync hooks from a remote configuration.
Lefthook version
1.7.17
Steps to reproduce
- Set
clone.defaultRemoteName
to something other thanorigin
.
For example:git config --global clone.defaultRemoteName github
- Define a
lefthook.yml
file withremotes
.
For example:remotes: - git_url: https://github.com/rainstormy/presets-lefthook ref: main configs: - dependencies.yml - quality-assurance.yml
- Run
lefthook install
to clone the remote repository. - Run
lefthook install
again to sync the hooks. This is when the error occurs. - Finally, if
clone.defaultRemoteName
was not configured prior to step 1, you can undo it again so that it won't mess things up later on your computer ๐git config --global --unset clone.defaultRemoteName
Expected results
Lefthook should not raise an error:
sync hooks: โ๏ธ (pre-push, post-checkout, post-rewrite, pre-commit)
Actual results
Couldn't sync from https://github.com/rainstormy/presets-lefthook. Will continue anyway: exit status 128
sync hooks: โ๏ธ (pre-push, post-checkout, post-rewrite, pre-commit)
Possible Solution
I think a possible solution would be to specify the --origin
flag when cloning the remote repository, as it would override the clone.defaultRemoteName
setting.
For example:
git -C .git/info/lefthook-remotes clone --quiet --depth 1 --origin origin --branch main https://github.com/rainstormy/presets-lefthook presets-lefthook-main
Logs / Screenshots
From step 3:
LEFTHOOK_VERBOSE=1 lefthook install
โ [lefthook] cmd: [git rev-parse --show-toplevel]
โ [lefthook] stdout: /home/sdi/repositories/rainstormy/updraft
โ [lefthook] cmd: [git rev-parse --git-path hooks]
โ [lefthook] stdout: .git/hooks
โ [lefthook] cmd: [git rev-parse --git-path info]
โ [lefthook] stdout: .git/info
โ [lefthook] cmd: [git rev-parse --git-dir]
โ [lefthook] stdout: .git
โ [lefthook] cmd: [git hash-object -t tree /dev/null]
โ [lefthook] stdout: 4b825dc642cb6eb9a060e54bf8d69288fbee4904
โ Searching config in:/home/sdi/repositories/rainstormy/updraft
โ Merging remote config: https://github.com/rainstormy/presets-lefthook: .git/info/lefthook-remotes/presets-lefthook-main/dependencies.yml
โ Merging remote config: https://github.com/rainstormy/presets-lefthook: .git/info/lefthook-remotes/presets-lefthook-main/quality-assurance.yml
โ Cloning remote config repository: .git/info/lefthook-remotes/presets-lefthook-main
โ [lefthook] cmd: [git -C .git/info/lefthook-remotes clone --quiet --depth 1 --branch main https://github.com/rainstormy/presets-lefthook presets-lefthook-main]
โ [lefthook] dir: /home/sdi/repositories/rainstormy/updraft
โ [lefthook] stdout:
โ Searching config in:/home/sdi/repositories/rainstormy/updraft
โ Merging remote config: https://github.com/rainstormy/presets-lefthook: .git/info/lefthook-remotes/presets-lefthook-main/dependencies.yml
โ Merging remote config: https://github.com/rainstormy/presets-lefthook: .git/info/lefthook-remotes/presets-lefthook-main/quality-assurance.yml
sync hooks: โ๏ธ (pre-commit, pre-push, post-checkout, post-rewrite)
From step 4:
LEFTHOOK_VERBOSE=1 lefthook install
โ [lefthook] cmd: [git rev-parse --show-toplevel]
โ [lefthook] stdout: /home/sdi/repositories/rainstormy/updraft
โ [lefthook] cmd: [git rev-parse --git-path hooks]
โ [lefthook] stdout: .git/hooks
โ [lefthook] cmd: [git rev-parse --git-path info]
โ [lefthook] stdout: .git/info
โ [lefthook] cmd: [git rev-parse --git-dir]
โ [lefthook] stdout: .git
โ [lefthook] cmd: [git hash-object -t tree /dev/null]
โ [lefthook] stdout: 4b825dc642cb6eb9a060e54bf8d69288fbee4904
โ Searching config in:/home/sdi/repositories/rainstormy/updraft
โ Merging remote config: https://github.com/rainstormy/presets-lefthook: .git/info/lefthook-remotes/presets-lefthook-main/dependencies.yml
โ Merging remote config: https://github.com/rainstormy/presets-lefthook: .git/info/lefthook-remotes/presets-lefthook-main/quality-assurance.yml
โ Updating remote config repository: .git/info/lefthook-remotes/presets-lefthook-main
โ [lefthook] cmd: [git -C .git/info/lefthook-remotes/presets-lefthook-main fetch --quiet --depth 1 origin main]
โ [lefthook] dir: /home/sdi/repositories/rainstormy/updraft
โ [lefthook] error: exit status 128
โ [lefthook] stdout:
โ [lefthook] stderr: fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Couldn't sync from https://github.com/rainstormy/presets-lefthook. Will continue anyway: exit status 128
sync hooks: โ๏ธ (pre-push, post-checkout, post-rewrite, pre-commit)
mrexox commented
Hey! Thank you for such a good finding! I'll prepare the fix ASAP
spdiswal commented
Awesome, thanks!!