Skip to content

Commit 0227ced

Browse files
committed
Avoid using backtick characters in commit subject
Backticks are disallowed in commit messages because they can be easily confused with single quotes on some terminals, reducing readability. Moreover, using backticks to highlight symbols or function names is unnecessary—plain text or simple single quotes provide sufficient clarity and emphasis. Change-Id: I6a1a78546f21fe3a227922ba10ff4d8837066648
1 parent 779564d commit 0227ced

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

scripts/commit-msg.hook

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,17 @@ validate_commit_message() {
265265
fi
266266
done
267267

268-
# 7. Do no write single worded commits
268+
# 7. Ensure the commit subject has more than one word.
269269
# ------------------------------------------------------------------------------
270270

271-
COMMIT_SUBJECT_WORDS=(${COMMIT_SUBJECT_TO_PROCESS})
272-
test "${#COMMIT_SUBJECT_WORDS[@]}" -gt 1
273-
test $? -eq 0 || add_warning 1 "Do no write single worded commits"
271+
if [ "$(echo "$COMMIT_SUBJECT_TO_PROCESS" | wc -w)" -le 1 ]; then
272+
add_warning 1 "Do not write single-word commits. Provide a descriptive subject"
273+
fi
274274

275-
# 7a. Do not mention C source filenames
276-
[[ ${COMMIT_SUBJECT_TO_PROCESS} =~ [_a-zA-Z0-9]+\.[ch]$ ]]
277-
test $? -eq 1 || add_warning 1 "Avoid mentioning C source filenames"
275+
# 7a. Avoid using C source filenames as the commit subject.
276+
if [[ "$COMMIT_SUBJECT_TO_PROCESS" =~ ^[_a-zA-Z0-9]+\.[ch]$ ]]; then
277+
add_warning 1 "Avoid mentioning C source filenames in the commit subject"
278+
fi
278279

279280
# 8. Use the body to explain what and why vs. how
280281
# ------------------------------------------------------------------------------
@@ -295,12 +296,12 @@ validate_commit_message() {
295296
[[ ${COMMIT_SUBJECT_TO_PROCESS} =~ ^[[:blank:]]+ ]]
296297
test $? -eq 1 || add_warning 1 "Do not start the subject line with whitespace"
297298

298-
# 10. Avoid single word commit messages in subject
299+
# 10. Disallow backticks anywhere in the commit message.
299300
# ------------------------------------------------------------------------------
300301

301-
word_count=$(echo "$COMMIT_SUBJECT_TO_PROCESS" | wc -w)
302-
test "$word_count" -gt 1
303-
test $? -eq 0 || add_warning 1 "Commit subject should contain more than one word. Summarize your changes"
302+
if sed '/^[[:space:]]*#/d;/^[[:space:]]*$/d' "$COMMIT_MSG_FILE" | grep -q "\`"; then
303+
add_warning 1 "Avoid using backticks in commit messages"
304+
fi
304305

305306
# 11. Avoid commit subject that simply states a file update (e.g. "Update console.c")
306307
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)