Skip to content

chore(hooks): add prepare-commit-msg normalizer#23

Open
tannn wants to merge 2 commits into
mainfrom
nightshift/commit-normalize
Open

chore(hooks): add prepare-commit-msg normalizer#23
tannn wants to merge 2 commits into
mainfrom
nightshift/commit-normalize

Conversation

@tannn
Copy link
Copy Markdown
Owner

@tannn tannn commented Apr 10, 2026

Summary

  • Adds git-hooks/prepare-commit-msg hook that automatically normalizes commit subject lines before the commit-msg validator runs
  • Lowercases the description portion after the Conventional Commits prefix (e.g. feat(ui): Add Xfeat(ui): add X)
  • Strips a trailing period from the subject line (e.g. fix: handle nil pointer.fix: handle nil pointer)

Behavior

The hook is a no-op in all safe cases:

  • Merge commits (COMMIT_SOURCE=merge)
  • Squash commits (COMMIT_SOURCE=squash)
  • Fixup commits (subject starts with fixup! or squash!)
  • Template-only messages (subject is empty or all comments)
  • Messages that don't match a Conventional Commits prefix (won't guess at normalization)
  • Messages that already conform (no changes needed)

No changes to scripts/setup-hooks.sh are needed — it already symlinks every file in git-hooks/ automatically.

Test plan

  • Commit with feat(ui): Add Dark Mode Toggle. — should normalize to feat(ui): add dark mode toggle
  • Commit with fix: handle nil pointer — should pass through unchanged
  • Merge commit — hook should be skipped entirely
  • Commit with no CC prefix — hook should be skipped entirely
  • Run bash scripts/setup-hooks.sh and verify prepare-commit-msg symlink is created

🤖 Generated with Claude Code

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Replace sub(old, new) with direct print of normalized line. The previous
implementation treated the subject as an ERE regex, causing silent failure
for scoped commits (e.g. feat(ui):) where parentheses are metacharacters.

Also fix comment accuracy: lowercases first char only, not full description.
Fix grep error suppression to only mask exit-1 (no match), not I/O errors.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
@tannn
Copy link
Copy Markdown
Owner Author

tannn commented Apr 10, 2026

Iteration 2 — fixes from review:

  • Critical fix: Replaced awk sub(old, new) with direct print new; done=1; next. The previous sub() call treated the subject line as an ERE regex, so parentheses in scopes like feat(ui): were interpreted as capturing groups, causing silent no-match and leaving the subject un-normalized.
  • Minor fix: Updated comment from "Lowercases the description portion" → "Lowercases the first character of the description".
  • Minor fix: Changed || true to || SUBJECT="" so grep I/O errors still propagate while exit-1 (no match) is handled gracefully.

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