#!/bin/sh
set -eu
. "$(dirname "$0")/attribution-guard.sh"

# Refuse to publish any commit that names an AI assistant vendor, including
# commits created with --no-verify or before the commit-msg hook existed.
zero=0000000000000000000000000000000000000000
while read -r local_ref local_sha remote_ref remote_sha; do
    [ "$local_sha" = "$zero" ] && continue
    if [ "$remote_sha" = "$zero" ]; then
        range="$local_sha --not --remotes"
    else
        range="$remote_sha..$local_sha"
    fi
    for commit in $(git rev-list $range); do
        if ! git log -n1 --format='%an <%ae>%n%cn <%ce>%n%B' "$commit" | reject_blocked_names; then
            echo "Push blocked: commit $commit carries AI vendor attribution." >&2
            exit 1
        fi
    done
done
printf '%s\n' '

DISCORD UPDATES: AFTER this push succeeds, drain the published commit queue.
Before handing control back to the user:
1. Run: pwsh -File tools/discord-updates.ps1 next
2. If status is next, inspect ONLY that commit with git show --first-parent SHA.
3. Write a concise plain-language summary; exclude API keys and credentials.
4. Preview, then post with its full SHA and SummaryFile using the tracked CLI.
5. Verify the Discord receipt, then repeat from step 1 until status is caught-up.
Do not stop after one post, reset the tracker, skip commits, or use raw webhooks.
Posting is already authorized. Reconcile uncertain delivery before continuing.
See AGENTS.md and tools/discord-updates.md for exact commands and recovery.
This hook is a reminder; posting begins only after a successful push.

' >&2
exit 0
