Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clone.defaultRemoteName in .gitconfig causes remote configurations to fail #826

Closed
spdiswal opened this issue Sep 28, 2024 · 2 comments · Fixed by #830
Closed

clone.defaultRemoteName in .gitconfig causes remote configurations to fail #826

spdiswal opened this issue Sep 28, 2024 · 2 comments · Fixed by #830
Labels
bug Something isn't working

Comments

@spdiswal
Copy link

🔧 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)
@spdiswal spdiswal added the bug Something isn't working label Sep 28, 2024
@mrexox
Copy link
Member

mrexox commented Sep 30, 2024

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

@spdiswal
Copy link
Author

Awesome, thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants