Skip to content

fix(commits): restrict trailer handling to the final body block - #232

Open
iamlasse wants to merge 2 commits into
marcus:mainfrom
iamlasse:chore/commit-normalize-iter2
Open

fix(commits): restrict trailer handling to the final body block#232
iamlasse wants to merge 2 commits into
marcus:mainfrom
iamlasse:chore/commit-normalize-iter2

Conversation

@iamlasse

@iamlasse iamlasse commented Aug 26, 2026

Copy link
Copy Markdown

Follow-up to #231 addressing the review's blocking findings on the commit message normalizer.

Blocking fixes

1. Trailers are only recognized in the last body block. wrapBody previously treated any Token: value-shaped line anywhere in the body as a git trailer and hoisted it into its own block, silently reordering message content — a mid-paragraph Note: ... line caused the prose after it to be merged into the preceding paragraph with the "trailer" moved below. Now the body is split into blank-line-separated blocks and only the final block is treated as a trailer block, and only when every line in it is trailer-shaped (matching where git itself recognizes trailers). Everything else is wrapped in place, preserving order. A trailer-shaped block followed by more prose is wrapped as prose.

2. CI skips merge commits. The commit-msg job now uses git rev-list --no-merges, so GitHub-generated Merge pull request #N ... commits no longer fail validation (verified: such a subject exits non-zero under commit normalize --check, and --no-merges drops it from the range).

Minor fixes

  • The 72-char subject limit is now checked after the trailing period is trimmed, so a 73-char subject ending in . trims to a conforming 72 instead of being rejected — matching the documented auto-fix.
  • Malformed scopes (feat(a)b):, feat():) are rejected with a new ErrInvalidScope sentinel.

Tests

New cases: mid-body Note: line stays prose in place; trailer-shaped block followed by prose wrapped as prose; trailing-period subject at the boundary; malformed and empty scopes; extra idempotency cases. Full suite, go vet, gofmt, and go build pass; the commit-msg hook rewrite and rejection paths were exercised end-to-end.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift


Automated by nightshift

Add internal/commits with a pure Normalize function enforcing the
project's Conventional Commits rules: known type set (feat, fix, docs,
style, refactor, perf, test, build, ci, chore, revert), optional scope,
lowercase imperative subject limited to 72 chars with no trailing
period, comment stripping, body wrapping at 72 columns, and verbatim
preservation of git trailer blocks. Wire it into the CLI as 'nightshift
commit normalize' (positional, --file, and stdin sources; --check
validates only), ship a commit-msg hook under scripts/, install it via
'make install-hooks', and add a CI job that validates every commit in a
pull request. Document the format in docs/commit-messages.md.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
Address review feedback on the commit message normalizer:

- wrapBody no longer hoists Token-shaped lines out of mid-body prose;
  git only recognizes trailers in the last block, so only the final
  block is kept verbatim as trailers (and only when every line in it
  is trailer-shaped); anything else is wrapped in place, preserving
  order

- the CI commit-messages job uses git rev-list --no-merges so GitHub
  merge commits do not fail validation

- the 72-char subject limit is checked after the trailing period is
  trimmed, matching the documented auto-fix

- malformed scopes such as feat(a)b) or feat() are rejected with a new
  ErrInvalidScope sentinel

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