#!/bin/sh
# prepare-commit-msg — AG-03 trailer enforcement.
#
# Guarantees the human ``Signed-off-by`` trailer on EVERY commit, including
# ``git commit -m`` (which bypasses the ``.gitmessage`` template wired by
# AG-18). Idempotent — ``--if-exists doNothing`` never duplicates a trailer
# the author already wrote.
#
# Scope: only the *constant* human signoff is added here (derived from
# ``git config user.{name,email}``). The ``Co-Authored-By`` trailer names the
# drafting agent + context size, which the committing agent adds itself — a
# hook cannot know which model authored the change.
#
# Active when ``git config core.hooksPath .githooks`` is set — see
# CONTRIBUTING.md (the federation cookiecutter / ``mgf-common catch-up`` wires
# this for a fresh clone; set it by hand otherwise).

msg_file="$1"
src="$2"

# Leave git-generated merge / squash messages alone.
case "$src" in
	merge | squash) exit 0 ;;
esac

git interpret-trailers --if-exists doNothing \
	--trailer "Signed-off-by: $(git config user.name) <$(git config user.email)>" \
	--in-place "$msg_file"
