diff --git a/.husky/pre-push b/.husky/pre-push index 79f15b82eda..cb2635679d2 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -29,7 +29,6 @@ pushes_head=false while read -r _local_ref local_sha _remote_ref _remote_sha; do [ "$local_sha" = "$zero" ] && continue if [ "$local_sha" != "$head" ]; then - # These checks read the working tree, which holds HEAD, not this commit. echo "pre-push: $local_sha is not the checked-out commit; leaving it to CI" continue fi @@ -37,6 +36,16 @@ while read -r _local_ref local_sha _remote_ref _remote_sha; do done [ "$pushes_head" = true ] || exit 0 +# Lint and type-check read the working tree, so they judge the pushed commit only when nothing they +# read differs from it: no uncommitted change to a tracked file and no untracked file the type-check +# could read (TypeScript, JavaScript under `allowJs`, JSON under `resolveJsonModule`). Otherwise +# they could fail a sound commit or pass a broken one. +if ! git diff --quiet HEAD || [ -n "$(git ls-files --others --exclude-standard -- \ + '*.ts' '*.tsx' '*.mts' '*.cts' '*.js' '*.jsx' '*.mjs' '*.cjs' '*.json')" ]; then + echo "pre-push: uncommitted changes or untracked source files; leaving lint, type-check and generated artifacts to CI" + exit 0 +fi + base=$(git merge-base HEAD origin/staging 2>/dev/null || true) if [ -z "$base" ]; then echo "pre-push: origin/staging not found, running the full lint and type-check"