feat: normalize and validate commit messages via commit-msg hook - #228
Open
ke23y wants to merge 2 commits into
Open
feat: normalize and validate commit messages via commit-msg hook#228ke23y wants to merge 2 commits into
ke23y wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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.scripts/commit-msg.sh, the gitcommit-msghook entrypoint that runs the normalizer and rejects the commit with a clear error if the type prefix is missing/unrecognized.scripts/install-hooks.sh, an idempotent installer that symlinks bothcommit-msg.shand the existingpre-commit.shinto.git/hooks/.make install-hooks(previously pre-commit only).scripts/test-commit-msg-normalize.sh(plain bash, sincebatsisn't available in this environment) covering: unchanged already-conventional message, missing-colon insertion, unknown-type rejection, whitespace/blank-line cleanup, and body preservation.docs/guides/commit-message-format.mddocumenting the convention, install step, and--no-verifybypass.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 passscripts/commit-msg.sh <msgfile>manually verified to reject an unrecognized type with a clear error and non-zero exitscripts/install-hooks.shsymlinks 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)make install-hookson a clean checkout and confirm both hooks fire