Skip to content

fix(husky): make pre-commit reliable from linked git worktrees - #1145

Merged
tjcloa merged 1 commit into
developfrom
claude/gifted-fermat-77c7ec
Aug 6, 2026
Merged

fix(husky): make pre-commit reliable from linked git worktrees#1145
tjcloa merged 1 commit into
developfrom
claude/gifted-fermat-77c7ec

Conversation

@tjcloa

@tjcloa tjcloa commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What

Adds unset GIT_DIR GIT_WORK_TREE at the top of .husky/pre-commit, before turbo run test:staged and lint-staged.

Why

During git commit in a linked git worktree, git exports an absolute GIT_DIR (<main>/.git/worktrees/<name>) into the hook environment. Every child git call that jest --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 when GIT_DIR is set and no GIT_WORK_TREE is given.

Measured from packages/ethers-provider inside the hook: git diff --name-only HEAD reported 1667 phantom changed files (plus 1937 bogus untracked/modified, including node_modules). Consequences:

  • every package "detects changes", so unrelated suites run on each commit;
  • module resolution crosses checkout boundaries (worktrees nest inside the main checkout, so node's ancestor walk falls through to the main checkout's node_modules), crashing frontend tests with a duplicate-React error: Cannot read properties of null (reading 'useRef') in the packages/ui Tooltip.

In the main checkout git exports no GIT_DIR to the hook (only a relative GIT_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_FILE is deliberately kept so partial commits (git commit <paths>) still expose the temporary index to lint-staged.

Verification

  • Worktree commit (previously crashed): only the suite related to the staged file ran (sdk suite as positive control after touching an sdk test — 9/9 passed); all other packages reported "No tests found related to files changed since last commit"; lint-staged linted the staged .ts; commit succeeded.
  • Main-checkout commit: behavior unchanged (the unset is a no-op there — GIT_DIR was never exported); hook passed in ~8 s.
  • The commit in this PR was itself made from a fresh linked worktree through the fixed hook.

Reviewer notes

  • No change to --onlyChanged semantics or any package test:staged script; the hook is not weakened.
  • Hooks always run with cwd = repo/worktree top, so the top-level npx turbo / npx lint-staged invocations are unaffected by the unset.

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).
@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for sovryn-dapp ready!

Name Link
🔨 Latest commit 108311f
🔍 Latest deploy log https://app.netlify.com/projects/sovryn-dapp/deploys/6a750ea3fb820b0008236297
😎 Deploy Preview https://deploy-preview-1145.preview.sovryns.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 108311f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@tjcloa
tjcloa merged commit 0718468 into develop Aug 6, 2026
7 checks passed
@tjcloa
tjcloa deleted the claude/gifted-fermat-77c7ec branch August 6, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant