Skip to content

feat(commits): add breaking-change and commit-msg hook support - #203

Open
iamlasse wants to merge 2 commits into
marcus:mainfrom
iamlasse:feat/commit-normalize-hooks
Open

feat(commits): add breaking-change and commit-msg hook support#203
iamlasse wants to merge 2 commits into
marcus:mainfrom
iamlasse:feat/commit-normalize-hooks

Conversation

@iamlasse

@iamlasse iamlasse commented Aug 1, 2026

Copy link
Copy Markdown

Summary

Completes the Conventional Commits message normalizer into a fully spec-compliant, git-hook-ready tool. The base normalizer lived only in a local commit (c26c5fd), not on main; this PR brings it in and closes the remaining gaps.

Changes

  • Breaking-change support (internal/commits): parse the Conventional Commits 1.0.0 ! header indicator (feat!: / fix(api)!:), preserving the flag through parseHeader/formatHeader. Recognize the BREAKING CHANGE: / BREAKING-CHANGE: footer as a trailer and emit it verbatim instead of hard-wrapping it.
  • --check fixed (cmd/nightshift): validate-only — silent on success, single diagnostic + non-zero exit on failure, never rewriting the file. Previously it was a no-op that printed the normalized message.
  • In-place --file (cmd/nightshift): default mode rewrites the message file in place, but only when the result differs (no mtime churn on already-canonical messages), so a real commit-msg hook can normalize the actual commit.
  • Hook wiring (scripts/commit-msg.sh, Makefile): the commit-msg hook now drives the in-place rewrite and hints at breaking-change forms; make install-hooks installs both hooks.
  • Docs (README.md): documents both hooks and the Conventional Commits enforcement.
  • Tests: feat!:, fix(scope)!:, footer preservation + idempotency, and CLI behavior for --check / in-place --file.

Verification

gofmt, go vet ./..., go build ./..., and go test ./internal/commits/... ./cmd/nightshift/... all pass.

Closes the commit-normalize task.

Add internal/commits with pure Normalize/validate functions enforcing the project's Conventional Commits rules (known type set, lowercase type, lowercase subject, 72-char subject limit, whitespace trimming, and 72-column body wrapping). Wire it into the CLI as 'nightshift commit normalize' (positional, --file, and stdin sources; --check to validate only), ship a commit-msg git hook under scripts/, and document the format and installation in docs/commit-messages.md.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
Complete the Conventional Commits normalizer into a fully spec-compliant,
git-hook-ready tool.

* internal/commits: support the Conventional Commits 1.0.0 breaking-change
  header indicator ("feat!:" / "fix(api)!:"), preserving the flag through
  parseHeader/formatHeader. Recognize the "BREAKING CHANGE:" / "BREAKING-CHANGE:"
  footer as a trailer and emit it verbatim instead of hard-wrapping it.
* cmd/nightshift: make --check validate-only (silent on success, single
  diagnostic + non-zero exit on failure, never rewriting the file). Make
  --file rewrite the message in place when the result differs, so a real
  commit-msg hook can normalize the actual commit. Silence cobra usage noise.
* scripts/commit-msg.sh: drive the in-place --file rewrite; hint at the
  breaking-change forms in the rejection message.
* Makefile install-hooks: also install the commit-msg hook.
* README: document both hooks and the Conventional Commits enforcement.
* tests: cover "feat!:", "fix(scope)!:", footer preservation and idempotency,
  and CLI behavior for --check / in-place --file.

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