From cacb3123c770b5a9c01d622510b6e4ed64a2e8c1 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sat, 13 Sep 2025 22:59:32 +0800 Subject: [PATCH 1/2] Enforce queue function commit body requirement commit-msg hook now validates that commits mentioning queue functions (q_*) must include detailed explanations in the message body, as required by contributing guide. Change-Id: Idec84de41a8b072310f57c07471b6913cc05adbf --- scripts/commit-msg.hook | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index dc6171a14..1d40a0df8 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -394,25 +394,24 @@ validate_commit_message() { add_warning 1 "Do not write single-word commits. Provide a descriptive subject" fi - # 7a. Avoid using C source filenames as the commit subject. + # 7a. Avoid using C source filenames as the commit subject if [[ "${COMMIT_SUBJECT_TO_PROCESS}" =~ ^[_a-zA-Z0-9]+\.[ch]$ ]]; then add_warning 1 "Avoid mentioning C source filenames in the commit subject" fi - # 7b. Disallow parentheses in the commit subject. + # 7b. Disallow parentheses in the commit subject if [[ ${COMMIT_SUBJECT_TO_PROCESS} =~ [\(\)] ]]; then add_warning 1 "Avoid using parentheses '()' in commit subjects" fi - # 7c. Disallow conventional commit format (e.g., "chore(scope):", "feat:", etc.) + # 7c. Disallow conventional commit format # These formats waste precious characters from the 50-character limit # Check for patterns like "type:" or "type(scope):" with optional breaking change indicator if [[ ${COMMIT_SUBJECT} =~ ^[a-z]+\([^\)]+\):[[:space:]] ]] || [[ ${COMMIT_SUBJECT} =~ ^[a-z]+!?:[[:space:]] ]]; then add_warning 1 "Avoid conventional commit format (e.g., 'chore(scripts):', 'feat:', 'fix:'). Write a direct, descriptive subject" fi - # 7d. Alert if the commit subject starts with "Implementation" - # ------------------------------------------------------------------------------ + # 7d. Alert if the commit subject starts with non-imperative words if [[ "${COMMIT_SUBJECT_TO_PROCESS}" =~ ^(First|My|Implementation|Implementations|Creation|Modification|Queue) ]]; then add_warning 1 "Commit subject should use imperative mood" fi @@ -439,6 +438,14 @@ validate_commit_message() { fi fi + # 8a. For queue functions (q_*), require detailed explanation in body + # Check if subject mentions queue functions like "Implement q_size" or "Fix q_new" + if [[ "${COMMIT_SUBJECT}" =~ q_[a-zA-Z_]+ ]]; then + if [ "${NON_COMMENT_COUNT}" -le 1 ]; then + add_warning 1 "Queue function commits require detailed explanation in the body" + fi + fi + # 9. Do not start the subject line with whitespace # ------------------------------------------------------------------------------ From 805e2be4e9b2aa68f3acbb6ef5ef17e45da74231 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sat, 13 Sep 2025 23:11:14 +0800 Subject: [PATCH 2/2] Exclude repository filenames from spell check The commit-msg hook now filters out repository filenames when checking for spelling errors. Previously, mentioning files like CONTRIBUTING.md would incorrectly flag "md" as a misspelling, creating unnecessary friction when referencing project files in commit messages. Change-Id: I62d87d9f1ac5cd3ab9c992d49a2fc8331eadd5e0 --- scripts/commit-msg.hook | 42 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 1d40a0df8..ecd768ab7 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -503,12 +503,44 @@ validate_commit_message() { # Use aspell to list misspelled words according to American English, ignoring quoted text. MISSPELLED_WORDS=$(echo "$MSG_FOR_SPELLCHECK" | $ASPELL --lang=en --list --home-dir=scripts --personal=aspell-pws) - if [ -n "$MISSPELLED_WORDS" ]; then - results=$(get_all_match_positions "$MSG_FOR_SPELLCHECK_LINE_FINDING" "$MISSPELLED_WORDS") - while read -r result; do - add_warning "${result#*:}" "Avoid using non-American English words: ${result%%:*}" - done <<< "$results" + # Filter out words that are filenames in the git repository + if [ -n "$MISSPELLED_WORDS" ]; then + # Get comprehensive list of repository-related words to exclude + # 1. Full filenames with extensions + # 2. Filenames without extensions + # 3. Directory names + # 4. File extensions without the dot + GIT_WORDS=$( + { + # Full filenames + git ls-files 2>/dev/null | xargs -n1 basename 2>/dev/null + # Filenames without extensions + git ls-files 2>/dev/null | xargs -n1 basename 2>/dev/null | sed 's/\.[^.]*$//' + # Directory names + git ls-files 2>/dev/null | xargs -n1 dirname 2>/dev/null | tr '/' '\n' | grep -v '^\.$' + # File extensions (without dot) + git ls-files 2>/dev/null | grep '\.' | sed 's/.*\.//' + } | sort -u + ) + # Filter out repository filenames from misspelled words + FILTERED_MISSPELLED="" + while IFS= read -r word; do + # Check if the word matches any filename or file component + if ! echo "$GIT_WORDS" | grep -qxFi "$word"; then + FILTERED_MISSPELLED="$FILTERED_MISSPELLED$word"$'\n' + fi + done <<< "$MISSPELLED_WORDS" + + # Remove trailing newline + FILTERED_MISSPELLED="${FILTERED_MISSPELLED%$'\n'}" + if [ -n "$FILTERED_MISSPELLED" ]; then + results=$(get_all_match_positions "$MSG_FOR_SPELLCHECK_LINE_FINDING" "$FILTERED_MISSPELLED") + + while read -r result; do + add_warning "${result#*:}" "Avoid using non-American English words: ${result%%:*}" + done <<< "$results" + fi fi }