#!/bin/sh
# Run the release's local gates before pushing.

set -e

root=$(git rev-parse --show-toplevel)

if [ -x "$root/tools/release.sh" ]; then
	"$root/tools/release.sh" --gates || {
		echo "" >&2
		echo "pre-push: fix the above, or push with --no-verify if you mean it." >&2
		exit 1
	}
fi

# Keep local-only tool attribution out of public commit history.
range=$(git rev-parse --abbrev-ref --symbolic-full-name '@{upstream}' 2>/dev/null || echo "origin/main")
found=$(git log --format='%an <%ae>%n%B' "$range..HEAD" 2>/dev/null \
	| grep -niE 'generated with|co-authored' || true)
if [ -n "$found" ]; then
	echo "pre-push: the commits carry an attribution trailer:" >&2
	echo "$found" | sed 's/^/    /' >&2
	exit 1
fi
