From 9de8c61a532f8ded6fb12c5a9f5ca06c4d32ecf6 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Thu, 20 Feb 2025 11:35:02 +0800 Subject: [PATCH 1/2] Avoid single worded commits Change-Id: I7b5be0a71c065300daef9988e4a06ab27f6e387f --- scripts/commit-msg.hook | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 06cd638a9..166f79aee 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -260,8 +260,6 @@ validate_commit_message() { # 7. Use the body to explain what and why vs. how # ------------------------------------------------------------------------------ - # ? - # 8. Do no write single worded commits # ------------------------------------------------------------------------------ @@ -278,6 +276,13 @@ validate_commit_message() { [[ ${COMMIT_SUBJECT_TO_PROCESS} =~ ^[[:blank:]]+ ]] test $? -eq 1 || add_warning 1 "Do not start the subject line with whitespace" + + # 10. Avoid single word commit messages in subject + # ------------------------------------------------------------------------------ + + word_count=$(echo "$COMMIT_SUBJECT_TO_PROCESS" | wc -w) + test "$word_count" -gt 1 + test $? -eq 0 || add_warning 1 "Commit subject should contain more than one word (e.g. 'Update dependencies' instead of 'Update')" } unset GREP_OPTIONS From e4ad8ec2659e76f9b5d61c6b223b9d24ced2fdd5 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Thu, 20 Feb 2025 11:47:12 +0800 Subject: [PATCH 2/2] Avoid using just a filename like "Update qtest.c" Each git commit message subject should be sufficiently descriptive, and the commit hook will alert students who fail to provide meaningful and detailed subjects. Change-Id: Iaddd15b1020bee3e3ea518145a99f617ca438ccd --- scripts/commit-msg.hook | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 166f79aee..8a84f19e5 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -283,6 +283,15 @@ validate_commit_message() { word_count=$(echo "$COMMIT_SUBJECT_TO_PROCESS" | wc -w) test "$word_count" -gt 1 test $? -eq 0 || add_warning 1 "Commit subject should contain more than one word (e.g. 'Update dependencies' instead of 'Update')" + + # 11. Avoid commit subject that simply states a file update (e.g. "Update console.c") + if [[ $COMMIT_SUBJECT_TO_PROCESS =~ ^Update[[:space:]]+([^[:space:]]+)$ ]]; then + candidate="${BASH_REMATCH[1]}" + # Only warn if the candidate filename ends with .c or .h + if [[ $candidate =~ \.(c|h)$ ]]; then + add_warning 1 "Avoid using just a filename like '$candidate'. Provide a functional, meaningful description" + fi + fi } unset GREP_OPTIONS