#!/bin/sh
set -eu

# A Sites push is the required first step of publishing. Mirror its exact
# commit before allowing Sites to accept it. GitHub pushes do not recurse.
case "$2" in
  https://git.chatgpt-team.site/32f743eb-209d-405d-bbb7-b6cf46960ace/appgprj_6aa16855d0f8819198d015a1a8a1be26.git) ;;
  *) exit 0 ;;
esac

while read -r local_ref local_sha remote_ref remote_sha; do
  [ "$remote_ref" = refs/heads/main ] || continue
  if [ "$local_ref" = '(delete)' ]; then
    echo 'Refusing to delete the publishing branch.' >&2
    exit 1
  fi
  sh scripts/sync-github.sh "$local_sha"
done
