Repository navigation
fix: respect core.hooksPath set at worktree scope - #152
anandghegde wants to merge 2 commits into
Conversation
core.hooksPath was read with `git config --local`, which does not see the worktree scope (config.worktree). When it was set there, hooks were written to the default directory while git ran them from the configured one, so they never ran. Read the worktree scope first, then the local scope. Global and system config stay ignored.
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe hook directory lookup now checks Git worktree scope before local scope. It ignores global and system configuration, preserves default path handling, and adds tests for linked worktrees and a patch changeset. ChangesHooks path resolution
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🦋 Changeset detectedLatest commit: 3b21a9c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the review, @JounQin. Nothing outstanding on my side — the fix and its test are in a single commit, and CI is green. Happy to rebase or squash differently if that helps when you're ready to merge. |
_getRepoScopedHooksPath falls through to undefined when no repo-scoped core.hooksPath is set, which the caller's !customHooksDirPath check already handles. JSDoc updated to match.
Credit to @thomastaillefer for tracking this down and proposing the approach in #150; this PR implements it with tests.
_getHooksDirPath()readcore.hooksPathwithgit config --local, which can't see the worktree scope (.git/worktrees/<name>/config.worktree, used whenextensions.worktreeConfigis on). If the path was set there, the hook was written to the default.git/hookswhile git read hooks from the configured directory, so the hook never ran and nothing reported a problem.Fix
Read
core.hooksPathfrom the two repo-level scopes in the order git applies them:--worktreefirst, then--local. Errors are ignored and the next scope is tried.--worktreefails in a linked worktree whenextensions.worktreeConfigis off, and--getexits 1 when the key isn't set. Global and system config are still never consulted, so #130 stays fixed. Relative paths and the default<gitRoot>/hooksfallback are handled as before.Tests
Added to the existing "Git worktree support" block:
extensions.worktreeConfigis offcore.hooksPath(viaGIT_CONFIG_GLOBAL) is ignoredThe first two fail without the fix. The global-config test fails if the scope flags are dropped.
Verified
yarn test: 60 passed.yarn lint: clean. Both run on Node 22 with git 2.50.1 on macOS.core.hooksPathis invisible to--local, so hooks install where git never reads #150, using the localcli.js. Before the fix, the commit went through,customhooks/stayed empty and the hook landed inmain/.git/hooks. After the fix,HOOK_FIREDprinted, the commit was blocked and the hook was incustomhooks/.core.hooksPathat worktree scope and committed from a subdirectory of the worktree. The hook installed in<worktree>/.rel-hooksfired.Includes a patch changeset.
Fixes #150
Summary by CodeRabbit
core.hooksPathconfigured specifically for a Git worktree.core.hooksPathsettings are ignored to prevent unintended hook placement.