Git.Commands.Am (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git am.

Applies a series of patches from mailbox-formatted files. Supports three-way merges, keeping subject prefixes, adding sign-off lines, and controlling in-progress am sessions (abort, continue, skip).

Summary

Functions

Returns the argument list for git am.

Parses the output of git am.

Types

t()

@type t() :: %Git.Commands.Am{
  abort: boolean(),
  continue_: boolean(),
  directory: String.t() | nil,
  keep: boolean(),
  patches: [String.t()],
  quiet: boolean(),
  signoff: boolean(),
  skip: boolean(),
  three_way: boolean()
}

Functions

args(command)

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

Returns the argument list for git am.

When :abort, :continue_, or :skip is true, builds the corresponding control command. Otherwise builds the full am command with all applicable flags and patch file paths.

Examples

iex> Git.Commands.Am.args(%Git.Commands.Am{abort: true})
["am", "--abort"]

iex> Git.Commands.Am.args(%Git.Commands.Am{continue_: true})
["am", "--continue"]

iex> Git.Commands.Am.args(%Git.Commands.Am{skip: true})
["am", "--skip"]

iex> Git.Commands.Am.args(%Git.Commands.Am{patches: ["0001-fix.patch"]})
["am", "0001-fix.patch"]

iex> Git.Commands.Am.args(%Git.Commands.Am{patches: ["0001-fix.patch"], three_way: true, signoff: true})
["am", "--3way", "--signoff", "0001-fix.patch"]

iex> Git.Commands.Am.args(%Git.Commands.Am{directory: "/tmp/patches"})
["am", "/tmp/patches"]

parse_output(stdout, exit_code)

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

Parses the output of git am.

On success (exit code 0), returns {:ok, :done}. On failure, returns {:error, {stdout, exit_code}}.