Conventional Commits 검증 commit-msg 훅
커밋 메시지가 Conventional Commits 형식을 따르는지 검증하는 Git Hook 스크립트
#!/bin/bash
# 커밋 메시지 파일 경로
MSG_FILE=$1
COMMIT_MSG=$(cat "$MSG_FILE")
# Conventional Commits 정규식
# 형식: type(scope): description
REGEXP="^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?!?: .+"
if [[ ! $COMMIT_MSG =~ $REGEXP ]]; then
echo "Error: Invalid commit message format."
echo "Commit message must follow: <type>(<scope>): <description>"
echo "Valid types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert"
exit 1
fi
echo "Commit message validated successfully."