Git.Commands.Merge (git v0.7.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git merge.

Merges a branch, with --no-ff, --ff-only, --squash, --no-commit, --no-edit, --allow-unrelated-histories, --verify-signatures, GPG signing of the merge commit (-S/-S<keyid>), a message (-m), a strategy (-s), and strategy options (-X, repeatable). Also drives the in-progress merge with --abort, --continue, and --quit.

Summary

Functions

Returns the argument list for git merge.

Parses the output of git merge.

Types

t()

@type t() :: %Git.Commands.Merge{
  abort: boolean(),
  allow_unrelated_histories: boolean(),
  branch: String.t() | nil,
  continue: boolean(),
  ff_only: boolean(),
  gpg_sign: boolean() | String.t(),
  message: String.t() | nil,
  no_commit: boolean(),
  no_edit: boolean(),
  no_ff: boolean(),
  quit: boolean(),
  squash: boolean(),
  strategy: String.t() | nil,
  strategy_option: [String.t()],
  verify_signatures: boolean()
}

Functions

args(command)

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

Returns the argument list for git merge.

  • :abort/:continue/:quit build the corresponding in-progress-merge form.
  • Otherwise builds git merge [flags] <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"]

iex> Git.Commands.Merge.args(%Git.Commands.Merge{branch: "f", strategy_option: ["ours", "ignore-all-space"]})
["merge", "--strategy-option", "ours", "--strategy-option", "ignore-all-space", "f"]

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

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

iex> Git.Commands.Merge.args(%Git.Commands.Merge{branch: "feature", verify_signatures: true})
["merge", "--verify-signatures", "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/--continue/--quit (exit code 0), returns {:ok, :done}. For a branch merge (exit code 0), parses into a Git.MergeResult struct. On failure, returns {:error, {stdout, exit_code}}.