Skip to content

Commit e62fc29

Browse files
committed
Wrap the body at 72 characters
This commit fixes line length detection in commit 35ebb65 caused by interference from the prepare-commit-msg hook. Change-Id: I1feaff2b11cafe13fd265a85c82914e33feca827
1 parent a8d4325 commit e62fc29

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

scripts/commit-msg.hook

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,31 @@ validate_commit_message() {
251251

252252
URL_REGEX='^[[:blank:]]*(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]'
253253

254-
# Ensure the commit message lines are loaded into an array.
255-
readarray -t COMMIT_MSG_LINES < "$COMMIT_MSG_FILE"
256-
257-
for i in "${!COMMIT_MSG_LINES[@]}"; do
258-
LINE="${COMMIT_MSG_LINES[$i]}"
259-
# Trim leading and trailing whitespace.
260-
TRIMMED_LINE="${LINE#"${LINE%%[![:space:]]*}"}"
261-
TRIMMED_LINE="${TRIMMED_LINE%"${TRIMMED_LINE##*[![:space:]]}"}"
262-
LINE_NUMBER=$((i+1))
263-
if [ "${#TRIMMED_LINE}" -gt 72 ] && ! [[ "$TRIMMED_LINE" =~ $URL_REGEX ]]; then
264-
add_warning "$LINE_NUMBER" "Wrap the body at 72 characters (${#TRIMMED_LINE} chars)"
265-
fi
266-
done
254+
# Ensure the commit message lines are loaded into an array.
255+
readarray -t COMMIT_MSG_LINES < "$COMMIT_MSG_FILE"
256+
257+
for i in "${!COMMIT_MSG_LINES[@]}"; do
258+
# Skip the first line (the subject) because the limit applies to the body.
259+
if [ "$i" -eq 0 ]; then
260+
continue
261+
fi
262+
263+
LINE="${COMMIT_MSG_LINES[$i]}"
264+
265+
# Skip the line if it is a comment.
266+
if [[ "$LINE" =~ ^[[:space:]]*# ]]; then
267+
continue
268+
fi
269+
270+
# Trim leading and trailing whitespace.
271+
TRIMMED_LINE="${LINE#"${LINE%%[![:space:]]*}"}"
272+
TRIMMED_LINE="${TRIMMED_LINE%"${TRIMMED_LINE##*[![:space:]]}"}"
273+
LINE_NUMBER=$((i+1))
274+
275+
if [ "${#TRIMMED_LINE}" -gt 72 ] && ! [[ "$TRIMMED_LINE" =~ $URL_REGEX ]]; then
276+
add_warning "$LINE_NUMBER" "Wrap the body at 72 characters (${#TRIMMED_LINE} chars)"
277+
fi
278+
done
267279

268280
# 7. Ensure the commit subject has more than one word.
269281
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)