#!/bin/bash
# 与 CI 一致的检测在每次 push 前执行（含 tag），避免「push tag 后 CI 才报错」。
# Install: cp scripts/githooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push
# 跳过检测：PYCLAW_SKIP_PRE_PUSH=1 git push ...
# stdin: <remote> <url> <local_ref> <local_sha> <remote_ref> <remote_sha> per ref
set -e
if [ "${PYCLAW_SKIP_PRE_PUSH:-0}" = "1" ]; then
    echo "Pre-push: skipped (PYCLAW_SKIP_PRE_PUSH=1)."
    exit 0
fi
PY="${PYTHON:-python3}"
echo "Pre-push: running CI-equivalent tests ($PY) [branch and tag pushes]..."
# 与 CI 相同：pytest --cov=pyclaw --cov-report=term-missing tests/；-x 首失败即停
if [ "${PYCLAW_PRE_PUSH_TEST_MODE:-full}" = "incremental" ]; then
  "$PY" scripts/pytest_scope.py run --mode incremental --base "${PYCLAW_TEST_BASE:-origin/master}" -- --cov=pyclaw --cov-report=term-missing -x --tb=line tests/
else
  "$PY" -m pytest --cov=pyclaw --cov-report=term-missing tests/ -x --tb=line
fi
echo "Pre-push: tests OK."
