fix(husky): make pre-commit reliable from linked git worktrees - #1145
Merged
Conversation
During git commit in a linked worktree, git exports an absolute GIT_DIR (<main>/.git/worktrees/<name>) to hooks. Child git calls that turbo's test:staged runs in package subdirectories (jest --onlyChanged via jest-changed-files) then resolve the package dir itself as the top of the working tree: git diff --name-only HEAD reports ~1700 phantom changed files, unrelated suites run, and module resolution crosses into the main checkout (duplicate React -> "Cannot read properties of null (reading 'useRef')" in the packages/ui Tooltip; previously forced --no-verify on 4aee9cc1). Unset GIT_DIR (and GIT_WORK_TREE) at hook start so every child git call rediscovers the repo from its own cwd - correct in both the main checkout and linked worktrees. GIT_INDEX_FILE stays exported so partial commits keep exposing the temporary index to lint-staged. Verified: a commit from a linked worktree runs only suites related to the staged files (sdk suite as positive control) and lint-staged still lints staged ts files; main-checkout commits are unchanged (GIT_DIR was never exported there, so the unset is a no-op).
✅ Deploy Preview for sovryn-dapp ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
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.
What
Adds
unset GIT_DIR GIT_WORK_TREEat the top of.husky/pre-commit, beforeturbo run test:stagedandlint-staged.Why
During
git commitin a linked git worktree, git exports an absoluteGIT_DIR(<main>/.git/worktrees/<name>) into the hook environment. Every child git call thatjest --onlyChanged(jest-changed-files) makes from a package subdirectory then treats that package dir as the top of the working tree — git skips upward discovery whenGIT_DIRis set and noGIT_WORK_TREEis given.Measured from
packages/ethers-providerinside the hook:git diff --name-only HEADreported 1667 phantom changed files (plus 1937 bogus untracked/modified, includingnode_modules). Consequences:node_modules), crashing frontend tests with a duplicate-React error:Cannot read properties of null (reading 'useRef')in thepackages/uiTooltip.In the main checkout git exports no
GIT_DIRto the hook (only a relativeGIT_INDEX_FILE), which is why commits there were always fine.With the vars unset, each child git call rediscovers the repo from its own cwd — correct in both the main checkout and linked worktrees.
GIT_INDEX_FILEis deliberately kept so partial commits (git commit <paths>) still expose the temporary index to lint-staged.Verification
.ts; commit succeeded.GIT_DIRwas never exported); hook passed in ~8 s.Reviewer notes
--onlyChangedsemantics or any packagetest:stagedscript; the hook is not weakened.npx turbo/npx lint-stagedinvocations are unaffected by the unset.