#!/bin/sh
# post-commit — auto-push current branch to origin
#
# Feature branches get pushed automatically.
# main/master are deliberately SKIPPED — those require a CAB-approved
# push via the pre-push hook. Auto-pushing main bypasses that gate.
#
# P1 emergency: git push origin main --no-verify  (creates a retrospective obligation)
# Install via:  bash scripts/install-hooks.sh <repo-path>

branch=$(git symbolic-ref --short HEAD 2>/dev/null)
[ -z "$branch" ] && exit 0

# Never auto-push protected branches
case "$branch" in
  main|master)
    echo "ℹ️  post-commit: skipping auto-push for $branch (CAB gate required)" >&2
    exit 0
    ;;
esac

if ! git push origin "$branch" --quiet 2>&1; then
  echo "⚠️  post-commit: push to origin/$branch failed — run 'git push' manually" >&2
fi
