evilmartians/lefthook

`clone.defaultRemoteName` in `.gitconfig` causes remote configurations to fail

spdiswal opened this issue ยท 2 comments

๐Ÿ”ง 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

  1. Set clone.defaultRemoteName to something other than origin.
    For example:
    git config --global clone.defaultRemoteName github
  2. Define a lefthook.yml file with remotes.
    For example:
    remotes:
      - git_url: https://github.com/rainstormy/presets-lefthook
        ref: main
        configs:
          - dependencies.yml
          - quality-assurance.yml
  3. Run lefthook install to clone the remote repository.
  4. Run lefthook install again to sync the hooks. This is when the error occurs.
  5. 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)

Hey! Thank you for such a good finding! I'll prepare the fix ASAP

Awesome, thanks!!