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

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

Finds the best common ancestor(s) between two or more commits for use
in a three-way merge. Also supports checking ancestor relationships
and finding fork points.

# `t`

```elixir
@type t() :: %Git.Commands.MergeBase{
  all: boolean(),
  commits: [String.t()],
  fork_point: boolean(),
  independent: boolean(),
  is_ancestor: boolean(),
  octopus: boolean()
}
```

# `args`

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

Builds the argument list for `git merge-base`.

## Examples

    iex> Git.Commands.MergeBase.args(%Git.Commands.MergeBase{commits: ["main", "feature"]})
    ["merge-base", "main", "feature"]

    iex> Git.Commands.MergeBase.args(%Git.Commands.MergeBase{commits: ["main", "feature"], is_ancestor: true})
    ["merge-base", "--is-ancestor", "main", "feature"]

    iex> Git.Commands.MergeBase.args(%Git.Commands.MergeBase{commits: ["main", "feature"], all: true})
    ["merge-base", "--all", "main", "feature"]

    iex> Git.Commands.MergeBase.args(%Git.Commands.MergeBase{commits: ["a", "b", "c"], octopus: true})
    ["merge-base", "--octopus", "a", "b", "c"]

    iex> Git.Commands.MergeBase.args(%Git.Commands.MergeBase{commits: ["a", "b", "c"], independent: true})
    ["merge-base", "--independent", "a", "b", "c"]

    iex> Git.Commands.MergeBase.args(%Git.Commands.MergeBase{commits: ["main", "feature"], fork_point: true})
    ["merge-base", "--fork-point", "main", "feature"]

# `parse_output`

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

Parses the output of `git merge-base`.

The output mode depends on the flags used:

  * Default: returns `{:ok, String.t()}` with the ancestor SHA
  * With `is_ancestor: true`: exit 0 = `{:ok, true}`, exit 1 = `{:ok, false}`
  * With `all: true` or `independent: true`: returns `{:ok, [String.t()]}`

---

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