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

Implements the `Git.Command` behaviour for `git merge-file`.

`git merge-file` runs a scripted three-way file merge. It incorporates the
changes that lead from `base` to `other` into `current`, writing the merged
result (with conflict markers where the two sides overlap) back into the
`current` file. Nothing in the repository index or history is touched: this
operates purely on the three files on disk.

The process exit code carries the number of conflicts as a signal: `0` for a
clean merge, or the conflict count (clamped by git to `127`). Values of `128`
and above indicate a real error (bad option, missing file), not a conflict
count. `parse_output/2` distinguishes the two.

# `t`

```elixir
@type t() :: %Git.Commands.MergeFile{
  base: String.t() | nil,
  current: String.t() | nil,
  diff3: boolean(),
  labels: [String.t()],
  marker_size: pos_integer() | nil,
  other: String.t() | nil,
  ours: boolean(),
  quiet: boolean(),
  theirs: boolean(),
  union: boolean(),
  zdiff3: boolean()
}
```

# `args`

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

Returns the argument list for `git merge-file`.

## Examples

    iex> Git.Commands.MergeFile.args(%Git.Commands.MergeFile{current: "a", base: "o", other: "b"})
    ["merge-file", "a", "o", "b"]

    iex> Git.Commands.MergeFile.args(%Git.Commands.MergeFile{current: "a", base: "o", other: "b", ours: true})
    ["merge-file", "--ours", "a", "o", "b"]

    iex> Git.Commands.MergeFile.args(%Git.Commands.MergeFile{current: "a", base: "o", other: "b", labels: ["mine", "orig", "theirs"]})
    ["merge-file", "-L", "mine", "-L", "orig", "-L", "theirs", "a", "o", "b"]

# `parse_output`

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

Parses the output of `git merge-file`.

The exit code is the number of conflicts. A clean merge returns `{:ok, 0}`;
a merge that left conflict markers in the `current` file returns
`{:ok, count}` with `count > 0`. Exit codes of `128` or greater are real
errors and return `{:error, {stdout, exit_code}}`.

---

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