#!/bin/bash
#
# Pre-push Git Hook
#
# Runs local CI before allowing push to remote.
# This ensures code quality and packaging safety before sharing changes.
#
# Setup:
#   git config core.hooksPath githooks
#
# To skip (not recommended):
#   git push --no-verify
#

set -euo pipefail

# Get project root
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
cd "$PROJECT_ROOT"

echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Pre-push: Running local CI..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# Run local CI
if ./ci/run.sh; then
    echo ""
    echo "✅ Pre-push check passed - proceeding with push"
    exit 0
else
    echo ""
    echo "❌ Pre-push check failed - push blocked"
    echo ""
    echo "To skip this check (not recommended): git push --no-verify"
    exit 1
fi

