#!/bin/sh
# Pre-push hook — run the full gate before allowing a push to main.
#
# Install: ln -sf ../../scripts/pre-push .git/hooks/pre-push
#
# This runs the same checks as ci-checks.sh + wiki-lint --strict.
# If either fails, the push is rejected. The gate is deterministic,
# has no network calls, and completes in under 2 minutes on a warm build.
#
# Bypass (emergency only): git push --no-verify

set -eu

REPO_ROOT="$(git rev-parse --show-toplevel)"

echo "=== pre-push gate ==="
echo ""

cd "$REPO_ROOT"

# Full CI gate (fmt, clippy, test, markdown, wiki-lint --strict)
if ! ./scripts/ci-checks.sh; then
    echo ""
    echo "PRE-PUSH REJECTED: ci-checks.sh failed."
    echo "Fix the failures above, or push with --no-verify (emergency only)."
    exit 1
fi

echo ""
echo "=== pre-push gate: PASS ==="
