# `Git.Commands.Apply`
[🔗](https://github.com/joshrotenberg/git_wrapper_ex/blob/main/lib/git/commands/apply.ex#L1)

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.

# `t`

```elixir
@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()
}
```

# `args`

```elixir
@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`

```elixir
@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}}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
