#!/bin/sh
# Runs the same gates as CI before anything leaves this machine.
# Enable once per clone: git config core.hooksPath .githooks
# Skip in an emergency: git push --no-verify
# git built for Intel runs hooks under Rosetta on Apple Silicon; the native
# TypeScript compiler then looks for an x64 binary that is not installed.
if [ "$(uname -m)" = x86_64 ] && [ "$(sysctl -n hw.optional.arm64 2>/dev/null)" = 1 ]; then
  exec arch -arm64 /bin/sh "$0" "$@"
fi
log="$(git rev-parse --git-dir)/pre-push.log"
if npm run -s check </dev/null >"$log" 2>&1; then exit 0; fi
grep -v '^\.*$' "$log" | tail -40
echo "pre-push: gates failed; full output in $log" >&2
exit 1
