#!/bin/sh # Conventional Commits with a short subject; no AI attribution. # Called by lefthook as: commit-msg-check.sh msg_file="$1" subject=$(sed -n '1p' "$msg_file") case "$subject" in Merge\ * | Revert\ * | fixup!\ * | squash!\ * | amend!\ *) exit 0 ;; esac types='feat|fix|refactor|perf|docs|test|build|ci|chore|style|revert|exp' if ! printf '%s\n' "$subject" | grep -Eq "^($types)(\([a-z0-9._/-]+\))?!?: [^ ].*$"; then echo "commit-msg: subject must be '(): '" >&2 echo " types: ${types}" >&2 echo " got: $subject" >&2 exit 1 fi if [ "${#subject}" -gt 72 ]; then echo "commit-msg: subject is ${#subject} chars, keep it at 72 or less (aim for ~50)" >&2 exit 1 fi if grep -Eiq 'co-authored-by:[[:space:]]*claude|noreply@anthropic\.com|generated with \[?claude code' "$msg_file"; then echo "commit-msg: no AI attribution lines in commit messages" >&2 exit 1 fi