From e55a0a28cad573b39fb68df9f00a76dd1b0e78c4 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 8 Nov 2026 10:01:50 +0000 Subject: [PATCH] fix(commit-msg): reject whitespace-only descriptions --- README.md | 1 + commit-msg | 2 +- test/commit_msg_test.sh | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c24c756..9addf95 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,7 @@ format on your commit messages: Valid types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`. Add `!` after the type/scope for breaking changes. +Descriptions must contain at least one non-whitespace character. Merge commits and fixup/squash commits are always allowed. To disable this hook for a single commit: diff --git a/commit-msg b/commit-msg index 044dabd..9d0b39c 100755 --- a/commit-msg +++ b/commit-msg @@ -17,7 +17,7 @@ if echo "$msg" | grep -qE '^(fixup|squash)! '; then exit 0 fi -pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9_/-]+\))?!?: .+' +pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9_/-]+\))?!?: .*[^[:space:]].*' if ! echo "$msg" | grep -qE "$pattern"; then echo "ERROR: Commit message does not follow Conventional Commits format." diff --git a/test/commit_msg_test.sh b/test/commit_msg_test.sh index 349a767..48050fe 100644 --- a/test/commit_msg_test.sh +++ b/test/commit_msg_test.sh @@ -39,6 +39,8 @@ assert_rejected() { } run_hook 0 "feat: add checkout hook" +run_hook 0 "docs: clarify installation " +run_hook 0 $'fix: \tkeep a meaningful description' run_hook 0 "fix(shell/hooks): preserve lfs args" run_hook 0 "feat(api)!: change hook contract" run_hook 0 "Merge pull request #6 from taigrr/cd/clear-conflicting-hook-config" @@ -48,5 +50,9 @@ run_hook 0 "squash! test(shell): add regression coverage" assert_rejected "update hook behavior" assert_rejected "feature: add checkout hook" assert_rejected "fix(shell):" +assert_rejected "fix: " +assert_rejected "fix(shell): " +assert_rejected $'feat(api)!: \t\t' +assert_rejected $'docs: \t \r' echo "commit-msg regression tests passed"