Git.Commands.Apply (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git apply.

Applies a patch to files and/or to the index. Supports checking whether a patch applies cleanly, showing diffstat/summary, applying to the index or working tree, reverse application, and three-way merges.

Summary

Functions

Returns the argument list for git apply.

Parses the output of git apply.

Types

t()

@type t() :: %Git.Commands.Apply{
  cached: boolean(),
  check: boolean(),
  index: boolean(),
  patch: String.t() | nil,
  reverse: boolean(),
  stat: boolean(),
  summary: boolean(),
  three_way: boolean(),
  verbose: boolean()
}

Functions

args(command)

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

Returns the argument list for git apply.

Examples

iex> Git.Commands.Apply.args(%Git.Commands.Apply{patch: "fix.patch"})
["apply", "fix.patch"]

iex> Git.Commands.Apply.args(%Git.Commands.Apply{patch: "fix.patch", check: true})
["apply", "--check", "fix.patch"]

iex> Git.Commands.Apply.args(%Git.Commands.Apply{patch: "fix.patch", stat: true, summary: true})
["apply", "--stat", "--summary", "fix.patch"]

iex> Git.Commands.Apply.args(%Git.Commands.Apply{patch: "fix.patch", cached: true})
["apply", "--cached", "fix.patch"]

iex> Git.Commands.Apply.args(%Git.Commands.Apply{patch: "fix.patch", reverse: true})
["apply", "--reverse", "fix.patch"]

iex> Git.Commands.Apply.args(%Git.Commands.Apply{patch: "fix.patch", three_way: true})
["apply", "--3way", "fix.patch"]

parse_output(stdout, exit_code)

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

Parses the output of git apply.

For stat, summary, or check modes, returns {:ok, output} with the informational text. For normal apply operations, returns {:ok, :done}. On failure, returns {:error, {stdout, exit_code}}.