From 108311f059ab7b15690e0dbbcbbcda87184eebda Mon Sep 17 00:00:00 2001 From: Tyrone Johnson Date: Thu, 6 Aug 2026 22:58:01 +0300 Subject: [PATCH] fix(husky): make pre-commit reliable from linked git worktrees During git commit in a linked worktree, git exports an absolute GIT_DIR (
/.git/worktrees/) 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). --- .husky/pre-commit | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.husky/pre-commit b/.husky/pre-commit index 352cc725e..c338cd1f1 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,15 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" +# In linked git worktrees, git exports an absolute GIT_DIR to hooks. Child git +# calls that run in package subdirectories (jest --onlyChanged, via turbo) then +# treat their own cwd as the top of the working tree and report thousands of +# phantom changed files, so unrelated suites run with broken module resolution. +# Unset it so each git call rediscovers the repo from its cwd — correct in both +# the main checkout and linked worktrees. GIT_INDEX_FILE stays exported so +# partial commits (git commit ) still expose the temporary index to +# lint-staged. +unset GIT_DIR GIT_WORK_TREE + npx turbo run test:staged npx lint-staged