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.
Summary
Types
Functions
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"]
@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: trueorindependent: true: returns{:ok, [String.t()]}