# `Git.Patch`
[🔗](https://github.com/joshrotenberg/git_wrapper_ex/blob/main/lib/git/patch.ex#L1)

Higher-level patch workflow operations that compose `Git.format_patch/1`,
`Git.apply_patch/1`, and `Git.am/1`.

All functions accept an optional keyword list. Use `:config` to specify the
repository via a `Git.Config` struct; when omitted a default config is built
from the environment.

# `apply`

```elixir
@spec apply(
  String.t(),
  keyword()
) :: {:ok, :done} | {:ok, String.t()} | {:error, term()}
```

Applies a patch file to the working tree.

Delegates to `Git.apply_patch/1`.

## Options

  * `:config` - a `Git.Config` struct

## Examples

    {:ok, :done} = Git.Patch.apply("0001-fix.patch")

# `apply_mailbox`

```elixir
@spec apply_mailbox(
  [String.t()],
  keyword()
) :: {:ok, :done} | {:error, term()}
```

Applies mailbox-formatted patches (git am).

Delegates to `Git.am/1`.

## Options

  * `:config` - a `Git.Config` struct

## Examples

    {:ok, :done} = Git.Patch.apply_mailbox(["0001-fix.patch"])

# `check`

```elixir
@spec check(
  String.t(),
  keyword()
) :: {:ok, String.t()} | {:error, term()}
```

Checks whether a patch applies cleanly without actually applying it.

Uses `Git.apply_patch/1` with the `:check` option.

## Options

  * `:config` - a `Git.Config` struct

## Examples

    {:ok, _output} = Git.Patch.check("0001-fix.patch")

# `create`

```elixir
@spec create(
  String.t(),
  keyword()
) :: {:ok, [String.t()]} | {:ok, String.t()} | {:error, term()}
```

Creates patch files from commits starting at a ref.

Delegates to `Git.format_patch/1`.

## Options

  * `:config` - a `Git.Config` struct
  * `:output_directory` - directory to write patch files to

## Examples

    {:ok, files} = Git.Patch.create("HEAD~3")
    {:ok, files} = Git.Patch.create("HEAD~1", output_directory: "/tmp/patches")

---

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