@@ -249,36 +249,46 @@ validate_commit_message() {
249
249
# 6. Wrap the body at 72 characters
250
250
# ------------------------------------------------------------------------------
251
251
252
- URL_REGEX=' ^[[:blank:]]*(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]'
253
-
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
267
-
268
- # 7. Use the body to explain what and why vs. how
269
- # ------------------------------------------------------------------------------
252
+ URL_REGEX=' ^[[:blank:]]*(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]'
253
+
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
270
267
271
- # 8 . Do no write single worded commits
268
+ # 7 . Do no write single worded commits
272
269
# ------------------------------------------------------------------------------
273
270
274
271
COMMIT_SUBJECT_WORDS=(${COMMIT_SUBJECT_TO_PROCESS} )
275
272
test " ${# COMMIT_SUBJECT_WORDS[@]} " -gt 1
276
273
test $? -eq 0 || add_warning 1 " Do no write single worded commits"
277
274
278
- # 8a . Do not mention C source filenames
275
+ # 7a . Do not mention C source filenames
279
276
[[ ${COMMIT_SUBJECT_TO_PROCESS} =~ [_a-zA-Z0-9]+\. [ch]$ ]]
280
277
test $? -eq 1 || add_warning 1 " Avoid mentioning C source filenames"
281
278
279
+ # 8. Use the body to explain what and why vs. how
280
+ # ------------------------------------------------------------------------------
281
+
282
+ # Count non-comment, non-blank lines excluding "Change-Id:".
283
+ NON_COMMENT_COUNT=$( sed ' /^[[:space:]]*#/d;/^[[:space:]]*$/d;/^[[:space:]]*Change-Id:/d' " $COMMIT_MSG_FILE " | wc -l | xargs)
284
+
285
+ # If the subject is oversimplified for a queue function OR queue.c is modified,
286
+ # and there is only one meaningful line, issue a warning.
287
+ if { [[ " $COMMIT_SUBJECT_TO_PROCESS " =~ ^(Implement| Finish)[[:space:]]+q_[[:alnum:]_]+\( ? \) ? $ ]] || \
288
+ git diff --cached --name-only | grep -Eq ' (^|/)queue\.c$' ; } && [ " $NON_COMMENT_COUNT " -le 1 ]; then
289
+ add_warning 1 " Commit message oversimplified. Use the commit message body to explain what and why."
290
+ fi
291
+
282
292
# 9. Do not start the subject line with whitespace
283
293
# ------------------------------------------------------------------------------
284
294
0 commit comments