ref:main
#!/usr/bin/env bash
# commit-msg hook: enforce conventional commit format
set -euo pipefail

MSG_FILE="$1"
MSG=$(head -1 "$MSG_FILE")

# Allow merge commits, fixup, squash, amend, and Co-Authored-By
if echo "$MSG" | grep -qE '^(Merge |fixup! |squash! |amend! )'; then
  exit 0
fi

PATTERN='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?: .{10,}'

if ! echo "$MSG" | grep -qE "$PATTERN"; then
  echo "Invalid commit message:"
  echo "  $MSG"
  echo ""
  echo "Expected format: type: description (min 10 chars)"
  echo "  or:            type(scope): description"
  echo ""
  echo "Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
  exit 1
fi