#!/usr/bin/env bash
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"

push_lines="$(cat)"
while read -r local_ref local_sha remote_ref remote_sha; do
  if [ "$local_sha" = "0000000000000000000000000000000000000000" ]; then
    echo "[pre-push] 分支删除推送，跳过本地检查"
    exit 0
  fi
done <<< "$push_lines"

if [ "${SKIP_CHECKS:-0}" = "1" ]; then
  echo "[pre-push] SKIP_CHECKS=1，跳过本地检查"
  exit 0
fi

echo "[pre-push] 运行 backend check..."
npm --prefix apps/backend run check

echo "[pre-push] 运行 frontend check..."
npm --prefix apps/frontend run check

echo "[pre-push] 本地检查通过"
