Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions scripts/commit-msg.hook
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ------------------------------------------------------------------------------

Expand All @@ -278,6 +276,22 @@ 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')"

# 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
Expand Down
Loading