#!/bin/sh
# Reject commits that do not add or modify a session history log under session_history/.
# Keep this script LF-only so Git can execute it correctly on Windows checkouts.
# See CONTRIBUTING.md and AGENTS.md.

if [ -f .git/MERGE_HEAD ]; then
    exit 0
fi

found=0
while IFS= read -r path; do
    [ -z "$path" ] && continue
    case "$path" in
        session_history/*.md)
            if [ "$path" != "session_history/TEMPLATE.md" ]; then
                found=1
                break
            fi
            ;;
    esac
done <<EOF
$(git diff --cached --name-only --diff-filter=AMR)
EOF

if [ "$found" -eq 0 ]; then
    echo "pre-commit: blocked — this commit must add or update a session history file." >&2
    echo "  Add or edit a file matching: session_history/<YYYY-MM-DD>_<slug>.md" >&2
    echo "  (session_history/TEMPLATE.md alone does not satisfy this rule.)" >&2
    echo "  See CONTRIBUTING.md. Before committing, read that file and follow it." >&2
    exit 1
fi

exit 0
