Git.Commands.InterpretTrailers (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git interpret-trailers.

Adds or parses trailers in commit messages. Trailers are key-value pairs that appear at the end of a commit message, such as "Signed-off-by:" or "Co-authored-by:".

Summary

Functions

Returns the argument list for git interpret-trailers.

Parses the output of git interpret-trailers.

Types

t()

@type t() :: %Git.Commands.InterpretTrailers{
  file: String.t() | nil,
  if_exists: String.t() | nil,
  if_missing: String.t() | nil,
  in_place: boolean(),
  no_divider: boolean(),
  parse: boolean(),
  trailers: [String.t()],
  trim_empty: boolean(),
  unfold: boolean(),
  where: String.t() | nil
}

Functions

args(command)

@spec args(t()) :: [String.t()]

Returns the argument list for git interpret-trailers.

Examples

iex> Git.Commands.InterpretTrailers.args(%Git.Commands.InterpretTrailers{})
["interpret-trailers"]

iex> Git.Commands.InterpretTrailers.args(%Git.Commands.InterpretTrailers{parse: true})
["interpret-trailers", "--only-trailers"]

iex> Git.Commands.InterpretTrailers.args(%Git.Commands.InterpretTrailers{trailers: ["Signed-off-by: A"]})
["interpret-trailers", "--trailer", "Signed-off-by: A"]

iex> Git.Commands.InterpretTrailers.args(%Git.Commands.InterpretTrailers{in_place: true, file: "msg.txt"})
["interpret-trailers", "--in-place", "msg.txt"]

iex> Git.Commands.InterpretTrailers.args(%Git.Commands.InterpretTrailers{where: "end"})
["interpret-trailers", "--where", "end"]

iex> Git.Commands.InterpretTrailers.args(%Git.Commands.InterpretTrailers{if_exists: "replace"})
["interpret-trailers", "--if-exists", "replace"]

iex> Git.Commands.InterpretTrailers.args(%Git.Commands.InterpretTrailers{if_missing: "doNothing"})
["interpret-trailers", "--if-missing", "doNothing"]

parse_output(stdout, exit_code)

@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, String.t()} | {:error, {String.t(), non_neg_integer()}}

Parses the output of git interpret-trailers.

On success (exit code 0), returns {:ok, output} with the processed message or trailer text. On failure, returns {:error, {stdout, exit_code}}.