fix: prevent lefthook run from overwriting global hooks#1371
Merged
mrexox merged 2 commits intoevilmartians:masterfrom Apr 3, 2026
Merged
fix: prevent lefthook run from overwriting global hooks#1371mrexox merged 2 commits intoevilmartians:masterfrom
lefthook run from overwriting global hooks#1371mrexox merged 2 commits intoevilmartians:masterfrom
Conversation
syncHooks bypasses the ensureHooksPathUnset guard that Install() uses, silently overwriting global hooks when core.hooksPath is configured. These tests pin the expected behavior so the fix can be verified.
Install() and syncHooks() both create hook files but only Install() checked core.hooksPath first. This allowed the auto-install path (triggered by config changes during a commit) to silently overwrite a user's global hooks directory. Introduce installHooks() as the single entry point for hook creation, pairing ensureHooksPathUnset() with createHooksIfNeeded() so the guard can never be bypassed. syncHooks() now warns and skips when core.hooksPath is set, rather than overwriting the configured directory.
lefthook run from overwriting global hooks
Member
|
Thank you very much! The code looks good! I'll release the new version in a few days 👍 |
This was referenced Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey folks! 👋 This PR fixes a bug in lefthook that was causing it to overwrite global Git pre-commit hooks.
Context
When
git config --global core.hooksPathis set, but the local repo doesn't setgit config core.hooksPath,lefthook runoverwrites the hook.lefthook installdoesn't have this issue (it has a guard against this).Script to reproduce (runs in a throwaway Docker container): https://gist.github.com/ivy/36674310695d5d078a2ca9a25324113d
lefthook version
Changes
Red-green refactor:
core.hooksPathguard into a new shared method:installHooks()InstallandRuncodepaths to use the shared method