#!/usr/bin/env bash
# Prevent direct pushes to protected branches.

set -euo pipefail

protected_branches=("main")
current_branch="$(git symbolic-ref --short HEAD 2>/dev/null || echo '')"

if [ -z "$current_branch" ]; then
    exit 0
fi

for branch in "${protected_branches[@]}"; do
    if [ "$current_branch" = "$branch" ]; then
        echo ""
        echo "❌ ERROR: Direct push to '$branch' is not allowed."
        echo ""
        echo "Use a feature branch and open a Pull Request:"
        echo "  1. git switch -c feature/your-change"
        echo "  2. git push origin feature/your-change"
        echo ""
        exit 1
    fi
done

exit 0
