fix(prepare): install husky hooks in git worktrees - #151
Open
tomcasaburi wants to merge 1 commit into
Open
tomcasaburi wants to merge 1 commit into
tomcasaburi wants to merge 1 commit into
Conversation
The prepare guard `test -d .git` is false in a linked worktree, where .git
is a file, so husky install was skipped and .husky/_/husky.sh never
written. core.hooksPath is shared repo config, so the commit-msg hook still
ran and every commit in the worktree failed sourcing the missing file.
Use `test -e .git`, matching husky's own existsSync('.git') check.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 54 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
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 |
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.
Problem
preparewastest -d .git && husky install || true. In a linked git worktree.gitis a file, so husky was never installed there and.husky/_/husky.shwas missing.core.hooksPath=.huskyis shared repo config, so.husky/commit-msgstill ran, and every commit in the worktree failed:Reproduced with a fresh
git worktree addfromorigin/master, followed bynpm ciandgit commit.Fix
Change the guard to
test -e .git. This matches husky 8's own check (fs.existsSync('.git')). A file.gitalso covers submodules.Installs without a
.gitare unchanged:.gitvia.dockerignoreand installs with--ignore-scripts..git.Test
test/cli/prepare-husky.test.tsreads the realpreparescript frompackage.jsonand runs it in a temporary repo, both in the normal checkout and in a linked worktree. It asserts that.husky/_/husky.shexists afterwards. The worktree case fails on the old script and passes with the fix. The test is skipped on Windows, where npm runs scripts through cmd.exe.npm run build && npm run build:testpassnpm run test:cli: 45 files, 344 tests passed, 1 skippedCloses #150