Expand description
commit-msg — validate the summary line and reformat the message.
Validates: a subject is present and within the subject limit; it carries a conventional type prefix; a description follows, within the description budget. Formats: place the type’s gitmoji where the repository asked for it, hard-wrap the body, and group the trailing footers with one blank line before them.
Every limit and the emoji placement are commit_style settings — four
git config keys with shipped defaults. What this hook enforces is
configurable; that it enforces is not.
Two invariants hold across all four gitmoji placements:
- The limits measure what you wrote. Decoration this hook added is removed before anything is counted, so the emoji can never eat the budget — and re-checking an already-decorated subject counts the same characters the author was told about the first time.
- Re-running is a no-op.
--amend, a rebase reword and a--no-verifyretry all hand this hook a subject it already wrote. Seeundecorate.
Ported from ~190 lines of JS. The one structural simplification is how the
optional leading emoji is recognised — see split_leading_emoji.
Structs§
- Subject
- Undecorated
- A subject with the decoration this hook itself applied taken back off.
Functions§
- group_
footer - Separate the trailing run of footer lines, drop blanks inside it, and put exactly one blank line before the group.
- is_
footer - A trailing footer line:
Key-Word: value,BREAKING CHANGE: …,Refs: #1, or blank. - parse_
subject ^\s*(emoji)?\s*(type)(\(scope\))?(!)?:\s*(.*)$over the FIRST line only.- run
- split_
leading_ emoji - Skip a leading emoji cluster.
- strip_
comments - Drop full-line comments, as git itself does.
- undecorate
- Take off a leading gitmoji that this hook wrote.
- wrap
- Greedy hard wrap at
width, breaking on spaces — the JS(?![^\n]{1,w}$)([^\n]{1,w})\sreplace. A word longer thanwidthis left intact rather than split.