From f88926f8a8a6584f1acdeed083945de518eb64a7 Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Fri, 5 Dec 2025 17:24:47 +0900 Subject: [PATCH] =?UTF-8?q?git=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- work/scripts/check-commit-message-rules.sh | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 work/scripts/check-commit-message-rules.sh diff --git a/work/scripts/check-commit-message-rules.sh b/work/scripts/check-commit-message-rules.sh new file mode 100755 index 0000000..db3a9a1 --- /dev/null +++ b/work/scripts/check-commit-message-rules.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Check if a commit message follows project rules +# Rules: 50/72 formatting, no advertisements/branding +# Usage: ./check-commit-message-rules.sh [commit-hash] +# If no commit-hash is provided, checks the latest commit + +# Determine which commit to check +if [ $# -eq 0 ]; then + commit_ref="HEAD" + echo "Checking latest commit..." +else + commit_ref="$1" + echo "Checking commit: $commit_ref" +fi + +# Get the commit message +commit_message=$(git log -1 --pretty=format:"%s%n%b" "$commit_ref") + +# Split into subject and body +subject=$(echo "$commit_message" | head -n1) +body=$(echo "$commit_message" | tail -n +2 | sed '/^$/d') + +echo "Checking commit message format..." +echo "Subject: $subject" + +# Check subject line length +subject_length=${#subject} +if [ $subject_length -gt 50 ]; then + echo "[FAIL] Subject line too long: $subject_length characters (max 50)" + exit_code=1 +else + echo "[PASS] Subject line length OK: $subject_length characters" + exit_code=0 +fi + +# Check body line lengths if body exists +if [ -n "$body" ]; then + echo "Checking body line lengths..." + while IFS= read -r line; do + line_length=${#line} + if [ $line_length -gt 72 ]; then + echo "[FAIL] Body line too long: $line_length characters (max 72)" + echo "Line: $line" + exit_code=1 + fi + done <<< "$body" + + if [ $exit_code -eq 0 ]; then + echo "[PASS] All body lines within 72 characters" + fi +else + echo "[INFO] No body content to check" +fi + +# Check for advertisements, branding, or promotional content +echo "Checking for advertisements and branding..." +if echo "$commit_message" | grep -qi "generated with\|claude code\|anthropic\|co-authored-by.*claude\|🤖"; then + echo "[FAIL] Commit message contains advertisements, branding, or promotional content" + exit_code=1 +else + echo "[PASS] No advertisements or branding detected" +fi + +if [ $exit_code -eq 0 ]; then + echo "[PASS] Commit message follows all rules" +else + echo "[FAIL] Commit message violates project rules" +fi + +exit $exit_code