#!/bin/bash
# Commit-msg hook to validate commit message format

COMMIT_MSG_FILE=$1
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")

# Skip merge commits
if grep -q "^Merge" "$COMMIT_MSG_FILE"; then
    exit 0
fi

# Count words in first line (commit summary)
WORD_COUNT=$(echo "$COMMIT_MSG" | head -n1 | wc -w | tr -d ' ')

if [ $WORD_COUNT -lt 3 ]; then
    echo "❌ Commit message must be at least 3 words"
    echo "   Your message: '$COMMIT_MSG'"
    echo "   Word count: $WORD_COUNT"
    exit 1
fi

echo "✅ Commit message validated"
exit 0
