Skip to content

Commit ea38d3c

Browse files
committed
fix(hooks): skip local lint and type-check when the working tree differs from the pushed commit
1 parent 7e6a296 commit ea38d3c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎.husky/pre-push‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,22 @@ pushes_head=false
2929
while read -r _local_ref local_sha _remote_ref _remote_sha; do
3030
[ "$local_sha" = "$zero" ] && continue
3131
if [ "$local_sha" != "$head" ]; then
32-
# These checks read the working tree, which holds HEAD, not this commit.
3332
echo "pre-push: $local_sha is not the checked-out commit; leaving it to CI"
3433
continue
3534
fi
3635
pushes_head=true
3736
done
3837
[ "$pushes_head" = true ] || exit 0
3938

39+
# Lint and type-check read the working tree, so they judge the pushed commit only when nothing they
40+
# read differs from it: no uncommitted change to a tracked file and no untracked TypeScript the
41+
# type-check would compile. Otherwise they could fail a sound commit or pass a broken one.
42+
if ! git diff --quiet HEAD ||
43+
[ -n "$(git ls-files --others --exclude-standard -- '*.ts' '*.tsx' '*.mts' '*.cts')" ]; then
44+
echo "pre-push: uncommitted changes or untracked TypeScript; leaving lint, type-check and generated artifacts to CI"
45+
exit 0
46+
fi
47+
4048
base=$(git merge-base HEAD origin/staging 2>/dev/null || true)
4149
if [ -z "$base" ]; then
4250
echo "pre-push: origin/staging not found, running the full lint and type-check"

0 commit comments

Comments
 (0)