Skip to content

Commit 41c6c1d

Browse files
authored
Merge pull request #188 from jserv/hook-improve
Improve git commit hook
2 parents 2edaad9 + e4ad8ec commit 41c6c1d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

scripts/commit-msg.hook

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ validate_commit_message() {
260260
# 7. Use the body to explain what and why vs. how
261261
# ------------------------------------------------------------------------------
262262

263-
# ?
264-
265263
# 8. Do no write single worded commits
266264
# ------------------------------------------------------------------------------
267265

@@ -278,6 +276,22 @@ validate_commit_message() {
278276

279277
[[ ${COMMIT_SUBJECT_TO_PROCESS} =~ ^[[:blank:]]+ ]]
280278
test $? -eq 1 || add_warning 1 "Do not start the subject line with whitespace"
279+
280+
# 10. Avoid single word commit messages in subject
281+
# ------------------------------------------------------------------------------
282+
283+
word_count=$(echo "$COMMIT_SUBJECT_TO_PROCESS" | wc -w)
284+
test "$word_count" -gt 1
285+
test $? -eq 0 || add_warning 1 "Commit subject should contain more than one word (e.g. 'Update dependencies' instead of 'Update')"
286+
287+
# 11. Avoid commit subject that simply states a file update (e.g. "Update console.c")
288+
if [[ $COMMIT_SUBJECT_TO_PROCESS =~ ^Update[[:space:]]+([^[:space:]]+)$ ]]; then
289+
candidate="${BASH_REMATCH[1]}"
290+
# Only warn if the candidate filename ends with .c or .h
291+
if [[ $candidate =~ \.(c|h)$ ]]; then
292+
add_warning 1 "Avoid using just a filename like '$candidate'. Provide a functional, meaningful description"
293+
fi
294+
fi
281295
}
282296

283297
unset GREP_OPTIONS

0 commit comments

Comments
 (0)