#!/bin/sh
set -eu

# The commit subject must follow Conventional Commits — a project convention that keeps
# history consistent and aligned with branch-name prefixes. (Releases are versioned by the
# manual workflow_dispatch bump input, not by parsing this subject.)
SUBJECT=$(head -1 "$1")

# Exempt git's auto-generated subjects (merge, revert, autosquash fixup/squash/amend).
case "$SUBJECT" in
  "Merge "*|"Revert "*|"fixup! "*|"squash! "*|"amend! "*) exit 0 ;;
esac

if ! printf '%s' "$SUBJECT" | grep -qE '^(feat|fix|chore|docs|style|refactor|test|ci|build|perf|revert)(\(.+\))?!?: .+'; then
  echo "ERROR: Commit subject must follow Conventional Commits." >&2
  echo "  Got:     $SUBJECT" >&2
  echo "  Example: feat: add hint button" >&2
  echo "  Types:   feat|fix|chore|docs|style|refactor|test|ci|build|perf|revert" >&2
  exit 1
fi
