pub fn commit_msg_script() -> StringExpand description
Return the body of the generated commit-msg hook. Exposed as a
pure function so tests can assert on the rendered script without
touching the filesystem, and so future hook variants (commit-msg,
pre-push, …) can share helpers from this module.
The script:
- Reads the in-progress commit message (path passed by git as
$1). - Locates the first non-empty non-comment line — git’s own
commit template puts
# Please enter the commit message…above the user’s first real line, andgit commit -vappends a diff dump prefixed with#. Both are stripped before the “is the message already prefixed?” check. - Bails out (exit 0) if that line already starts with an
emoji-ish prefix (a
casematch against the:shortcode:form + agrep -Efor unicode emoji codepoints). - Shells out to
gwm commit-prefix --unicode. Ifgwmis missing from$PATH, or the shell-out fails for any reason, the hook exits 0 cleanly — the goal is “never block a commit because the hook itself broke”. - Prepends the resolved prefix + a space to the message and
writes the result back to the same file. Every filesystem
step here is guarded by
|| exit 0so a transient failure (full /tmp, noexec mount, read-only fs, …) lets the original commit through unmodified rather than aborting it.