fix(githooks): shorten commit-msg hook diagnostics

Long echo strings broke the same eighty-column rule the hook enforces on log
messages. Error output is split so the hook file itself stays readable.

- Wrap rejection messages to eighty columns or fewer
- Keep wording aligned with subject, summary, and bullet layout rules
This commit is contained in:
Jukka Aho
2026-05-11 02:51:11 +03:00
parent cded31c388
commit f663fda6f7
+14 -16
View File
@@ -27,7 +27,7 @@ while IFS= read -r line || [[ -n "${line}" ]]; do
if ((len > 80)); then if ((len > 80)); then
echo "❌ COMMIT MESSAGE: line ${lineno} is ${len} chars (max 80)" echo "❌ COMMIT MESSAGE: line ${lineno} is ${len} chars (max 80)"
echo "" echo ""
echo "Required layout: subject, blank, summary paragraph, blank, bullets." echo "Required: subject, blank, summary, blank, then \"- ...\" bullets."
echo "See .github/prompts/commit.prompt.md" echo "See .github/prompts/commit.prompt.md"
echo "" echo ""
echo "Offending line (truncated for display):" echo "Offending line (truncated for display):"
@@ -40,7 +40,7 @@ done <"${msg_file}"
# Drop trailing empty lines so optional final newline does not confuse counts. # Drop trailing empty lines so optional final newline does not confuse counts.
while ((${#lines[@]} > 0)); do while ((${#lines[@]} > 0)); do
last=$(( ${#lines[@]} - 1 )) last=$(( ${#lines[@]} - 1 ))
if [[ -z ${lines[last]} ]]; then if [[ -z "${lines[last]}" ]]; then
unset "lines[last]" unset "lines[last]"
else else
break break
@@ -49,8 +49,8 @@ done
n=${#lines[@]} n=${#lines[@]}
if ((n < 5)); then if ((n < 5)); then
echo "❌ COMMIT MESSAGE: need subject, blank, summary, blank, then bullets" echo "❌ COMMIT MESSAGE: need subject, blank, summary, blank, bullets"
echo "(at least five lines). See .github/prompts/commit.prompt.md" echo "(five or more lines). See .github/prompts/commit.prompt.md"
exit 1 exit 1
fi fi
@@ -81,8 +81,8 @@ if ((bullet_idx < 0)); then
fi fi
if ((bullet_idx < 3)); then if ((bullet_idx < 3)); then
echo "❌ COMMIT MESSAGE: add at least one summary line after the subject blank" echo "❌ COMMIT MESSAGE: add a summary line after the subject blank line"
echo "before the separator blank and bullets." echo "before the blank that precedes bullets."
exit 1 exit 1
fi fi
@@ -96,9 +96,8 @@ has_summary=0
for ((i = 2; i < bullet_idx - 1; i++)); do for ((i = 2; i < bullet_idx - 1; i++)); do
line=${lines[i]} line=${lines[i]}
if [[ -n "${line}" ]] && [[ "${line}" =~ ^[[:space:]]*-[[:space:]] ]]; then if [[ -n "${line}" ]] && [[ "${line}" =~ ^[[:space:]]*-[[:space:]] ]]; then
echo "❌ COMMIT MESSAGE: line $((i + 1)) looks like a bullet but is above" echo "❌ COMMIT MESSAGE: summary line $((i + 1)) starts like a bullet"
echo "the summary block; write prose summary lines first, then a blank" echo "Use prose first, one blank line, then hyphen bullets."
echo "line, then \"- ...\" bullets."
exit 1 exit 1
fi fi
if [[ -n "${line}" ]]; then if [[ -n "${line}" ]]; then
@@ -107,22 +106,21 @@ for ((i = 2; i < bullet_idx - 1; i++)); do
done done
if ((has_summary == 0)); then if ((has_summary == 0)); then
echo "❌ COMMIT MESSAGE: summary paragraph is empty (need 13 sentences before" echo "❌ COMMIT MESSAGE: summary paragraph is empty before the bullet list"
echo "the blank line that precedes bullets)." echo "Add one to three sentences, then a blank line, then bullets."
exit 1 exit 1
fi fi
for ((i = bullet_idx; i < n; i++)); do for ((i = bullet_idx; i < n; i++)); do
line=${lines[i]} line=${lines[i]}
if [[ -z "${line}" ]]; then if [[ -z "${line}" ]]; then
echo "❌ COMMIT MESSAGE: line $((i + 1)) is empty inside the bullet block;" echo "❌ COMMIT MESSAGE: empty line $((i + 1)) inside bullet block"
echo "remove blank lines between bullets or end the message after the last" echo "Remove blanks between bullets or end after the last bullet."
echo "bullet."
exit 1 exit 1
fi fi
if ! [[ "${line}" =~ ^[[:space:]]*-[[:space:]] ]]; then if ! [[ "${line}" =~ ^[[:space:]]*-[[:space:]] ]]; then
echo "❌ COMMIT MESSAGE: line $((i + 1)) must be a \"- ...\" bullet after the" echo "❌ COMMIT MESSAGE: line $((i + 1)) is not a hyphen bullet"
echo "summary section." echo "Each bullet line must start with dash then space after summary."
exit 1 exit 1
fi fi
done done