Skip to content

feat: normalize and validate commit messages via commit-msg hook - #228

Open
ke23y wants to merge 2 commits into
marcus:mainfrom
ke23y:feat/commit-normalize-msg-hook2
Open

feat: normalize and validate commit messages via commit-msg hook#228
ke23y wants to merge 2 commits into
marcus:mainfrom
ke23y:feat/commit-normalize-msg-hook2

Conversation

@ke23y

@ke23y ke23y commented Aug 23, 2026

Copy link
Copy Markdown

Summary

  • Adds scripts/commit-msg-normalize.sh, a dependency-free shell script that normalizes a commit message file: trims trailing whitespace, collapses extra blank lines, lowercases/validates the Conventional Commits type prefix (feat|fix|docs|refactor|test|chore|perf|ci), inserts a missing : after the type, and warns (non-blocking) if the subject exceeds 72 chars.
  • Adds scripts/commit-msg.sh, the git commit-msg hook entrypoint that runs the normalizer and rejects the commit with a clear error if the type prefix is missing/unrecognized.
  • Adds scripts/install-hooks.sh, an idempotent installer that symlinks both commit-msg.sh and the existing pre-commit.sh into .git/hooks/.
  • Wires the installer into make install-hooks (previously pre-commit only).
  • Adds scripts/test-commit-msg-normalize.sh (plain bash, since bats isn't available in this environment) covering: unchanged already-conventional message, missing-colon insertion, unknown-type rejection, whitespace/blank-line cleanup, and body preservation.
  • Adds docs/guides/commit-message-format.md documenting the convention, install step, and --no-verify bypass.
  • Updates README.md's "Pre-commit hooks" section to mention the new commit-msg hook.

Test plan

  • bash scripts/test-commit-msg-normalize.sh — 9/9 assertions pass
  • scripts/commit-msg.sh <msgfile> manually verified to reject an unrecognized type with a clear error and non-zero exit
  • scripts/install-hooks.sh symlinks both hooks into .git/hooks/; hooks were live during this branch's own commit (pre-commit gofmt/vet/build passed, commit-msg validated this PR's commit message)
  • Reviewer: run make install-hooks on a clean checkout and confirm both hooks fire

ke23y added 2 commits August 23, 2026 01:09
Adds scripts/commit-msg-normalize.sh (Conventional Commits subset:
feat/fix/docs/refactor/test/chore/perf/ci), scripts/commit-msg.sh as
the git hook entrypoint, and scripts/install-hooks.sh as an idempotent
installer for both commit-msg and the existing pre-commit hook. Wires
install-hooks.sh into `make install-hooks` and documents the
convention in docs/guides/commit-message-format.md and README.md.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
The commit-msg hook rejected standard merge and revert commit
messages because they don't start with a Conventional Commits type
prefix, blocking those routine operations unless hooks were bypassed
every time. Skip normalization/validation when git's commit-source
arg is merge/squash, or when the subject looks like a Merge/Revert
message.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant