Git.Commands.Merge (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git merge.

Supports merging a branch, the --no-ff flag to force a merge commit, and --abort to abort an in-progress merge.

Summary

Functions

Returns the argument list for git merge.

Parses the output of git merge.

Types

t()

@type t() :: %Git.Commands.Merge{
  abort: boolean(),
  branch: String.t() | nil,
  no_ff: boolean(),
  squash: boolean()
}

Functions

args(command)

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

Returns the argument list for git merge.

  • When :abort is true, builds git merge --abort.
  • Otherwise builds git merge [--no-ff] <branch>.

Examples

iex> Git.Commands.Merge.args(%Git.Commands.Merge{branch: "feature"})
["merge", "feature"]

iex> Git.Commands.Merge.args(%Git.Commands.Merge{branch: "feature", no_ff: true})
["merge", "--no-ff", "feature"]

iex> Git.Commands.Merge.args(%Git.Commands.Merge{abort: true})
["merge", "--abort"]

iex> Git.Commands.Merge.args(%Git.Commands.Merge{branch: "feature", squash: true})
["merge", "--squash", "feature"]

parse_output(stdout, exit_code)

@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, Git.MergeResult.t()}
  | {:ok, :done}
  | {:error, {String.t(), non_neg_integer()}}

Parses the output of git merge.

For --abort operations (exit code 0), returns {:ok, :done}. For merge operations (exit code 0), parses into a Git.MergeResult struct. On failure, returns {:error, {stdout, exit_code}}.