From 821cbbd8135e7c91e754fbb11613166fc8bc2eee Mon Sep 17 00:00:00 2001 From: Brian O'Kelley Date: Mon, 17 Aug 2026 08:25:51 +0200 Subject: [PATCH] fix: isolate git hooks per worktree --- .conductor/settings.toml | 2 +- .husky/pre-commit | 7 ++++++- .husky/pre-push | 5 +++++ package.json | 2 +- scripts/configure-git-hooks.sh | 16 ++++++++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100755 scripts/configure-git-hooks.sh diff --git a/.conductor/settings.toml b/.conductor/settings.toml index 8de0424a0e..493aebe3dd 100644 --- a/.conductor/settings.toml +++ b/.conductor/settings.toml @@ -1,7 +1,7 @@ "$schema" = "https://conductor.build/schemas/settings.repo.schema.json" [scripts] -setup = "SETUP_NVM_SCRIPT=\"${NVM_DIR:-$HOME/.nvm}/nvm.sh\"; if [ -s \"$SETUP_NVM_SCRIPT\" ]; then . \"$SETUP_NVM_SCRIPT\" && nvm install 24.19.0 && nvm use 24.19.0; fi && node -e 'if (process.versions.node !== `24.19.0`) { console.error(`Node 24.19.0 is required; found ${process.versions.node}`); process.exit(1) }' && git config core.hooksPath .husky && npx --yes npm@10.9.4 ci && uv sync --frozen" +setup = "sh scripts/configure-git-hooks.sh && SETUP_NVM_SCRIPT=\"${NVM_DIR:-$HOME/.nvm}/nvm.sh\"; if [ -s \"$SETUP_NVM_SCRIPT\" ]; then . \"$SETUP_NVM_SCRIPT\" && nvm install 24.19.0 && nvm use 24.19.0; fi && node -e 'if (process.versions.node !== `24.19.0`) { console.error(`Node 24.19.0 is required; found ${process.versions.node}`); process.exit(1) }' && npx --yes npm@10.9.4 ci && uv sync --frozen" run_mode = "concurrent" [scripts.run.run] diff --git a/.husky/pre-commit b/.husky/pre-commit index 08c72fb57f..abf637c44b 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,9 @@ #!/bin/sh +HUSKY_INIT="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh" +[ -f "$HUSKY_INIT" ] && . "$HUSKY_INIT" +[ "${HUSKY-}" = "0" ] && exit 0 +export PATH="node_modules/.bin:$PATH" + bash scripts/check-image-quality.sh -npm run precommit \ No newline at end of file +npm run precommit diff --git a/.husky/pre-push b/.husky/pre-push index 5110e9fda2..5bf3cd3896 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,5 +1,10 @@ #!/bin/sh +HUSKY_INIT="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh" +[ -f "$HUSKY_INIT" ] && . "$HUSKY_INIT" +[ "${HUSKY-}" = "0" ] && exit 0 +export PATH="node_modules/.bin:$PATH" + # Verify version sync before pushing npm run verify-version-sync diff --git a/package.json b/package.json index 08c44020be..dbdcae0334 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "precommit": "bash scripts/with-timeout.sh 180 npm run test:unit && npm run test:test-dynamic-imports && npm run test:format-identity-boundaries && npm run test:callapi-state-change && bash scripts/with-timeout.sh 240 npm run precommit:server-unit && npm run typecheck", "test:storyboards": "bash scripts/run-storyboards-matrix.sh", "test:storyboards:3.0-compat": "bash scripts/run-storyboards-3-0-compat.sh", - "prepare": "husky", + "prepare": "sh scripts/configure-git-hooks.sh", "changeset": "changeset", "version": "changeset version && npm install --package-lock-only --ignore-scripts && npm run build:schemas -- --release && npm run build:compliance -- --release && npm run build:protocol-tarball -- --release && npm run sign:protocol-tarball", "sign:protocol-tarball": "bash scripts/sign-protocol-tarball.sh", diff --git a/scripts/configure-git-hooks.sh b/scripts/configure-git-hooks.sh new file mode 100755 index 0000000000..e4112a8a44 --- /dev/null +++ b/scripts/configure-git-hooks.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -eu + +# Match Husky's behavior for source archives and other installs without Git +# metadata: dependency installation should still succeed, just without hooks. +if [ ! -e .git ] || ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + exit 0 +fi + +# core.hooksPath is otherwise shared by every linked worktree. A per-worktree +# value prevents a stale checkout from redirecting another worktree's hooks. +# Point directly at the tracked hooks so a failed dependency install cannot +# leave hooks disabled because Husky's ignored shim directory was not generated. +git config extensions.worktreeConfig true +git config --worktree core.hooksPath .husky