# Block direct pushes to protected branches. Code must reach dev/main via a PR.
# Reads the refs being pushed from stdin (git passes "<local-ref> <local-sha> <remote-ref> <remote-sha>" per ref).

protected_branches="main dev"

while read -r local_ref local_sha remote_ref remote_sha; do
  # remote_ref looks like refs/heads/<branch>
  branch="${remote_ref#refs/heads/}"
  for protected in $protected_branches; do
    if [ "$branch" = "$protected" ]; then
      echo ""
      echo "✋ Direct push to '$protected' is blocked."
      echo "   Please open a pull request to get your changes into '$protected'."
      echo ""
      exit 1
    fi
  done
done

exit 0
