GitTrailers (GitTrailers v1.0.0)
View SourceParses, serializes, and manipulates Git commit-message trailers.
Trailer blocks are detected using the rules from
git-interpret-trailers(1), including folded values, the 25% rule,
configurable separators, and patch-divider handling. All operations are
performed on in-memory binaries without invoking Git or reading repository
configuration.
parse/2 is total for binary message content: text that does not contain an
accepted trailer block returns an empty trailers list. Invalid arguments
and options raise ArgumentError.
Summary
Functions
Adds trailers to a commit message using Git-compatible placement policies.
Formats one trailer as key<separator> value.
Parses the accepted trailer block at the end of message.
Serializes trailers in canonical Key: value form, joined with LF.
Types
@type if_exists() ::
:add_if_different_neighbor | :add_if_different | :add | :replace | :do_nothing
@type if_missing() :: :add | :do_nothing
@type where() :: :end | :start | :after | :before
Functions
@spec add(binary(), [trailer_input()], [add_option()]) :: binary()
Adds trailers to a commit message using Git-compatible placement policies.
Supported options are:
:where—:end,:start,:after, or:before; defaults to:end:if_exists—:add_if_different_neighbor,:add_if_different,:add,:replace, or:do_nothing; defaults to:add_if_different_neighbor:if_missing—:addor:do_nothing; defaults to:add:trim_empty— remove trailers with whitespace-only values; defaults tofalse:separators— accepted separators and the source of the first separator used for inserted lines; defaults to":":divider— insert before patch divider material; defaults totrue
Existing messages are returned byte-for-byte when no mutation is required. Changed trailer blocks use LF and canonical spacing while bytes outside the block are preserved.
@spec format(trailer_input(), binary()) :: binary()
Formats one trailer as key<separator> value.
The separator must be one non-whitespace character. The key and value are trimmed, and values containing CR or LF are rejected.
@spec parse(binary(), [parse_option()]) :: {:ok, GitTrailers.Result.t()}
Parses the accepted trailer block at the end of message.
Supported options are:
:separators— accepted separator characters; defaults to":":divider— stop before a patch divider; defaults totrue:unfold— join continuation lines with spaces; defaults totrue:known_keys— additional case-insensitive keys that satisfy Git's recognized-trailer requirement for the 25% rule
Source lines, including their original line endings, remain available in
each trailer's GitTrailers.Trailer.raw field.
@spec serialize([trailer_input()]) :: binary()
Serializes trailers in canonical Key: value form, joined with LF.
The returned binary does not have a terminal newline.