Skip to main content

Module commit_msg

Module commit_msg 

Source
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-verify retry all hand this hook a subject it already wrote. See undecorate.

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})\s replace. A word longer than width is left intact rather than split.