Git.Commands.CherryPick (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git cherry-pick.

Supports cherry-picking one or more commits, as well as aborting, continuing, and skipping in-progress cherry-pick operations.

Unsupported options

The --edit (-e) flag is intentionally not supported because it requires an interactive editor session, which cannot be driven by a non-interactive CLI wrapper.

Summary

Functions

Returns the argument list for git cherry-pick.

Parses the output of git cherry-pick.

Types

t()

@type t() :: %Git.Commands.CherryPick{
  abort: boolean(),
  allow_empty: boolean(),
  allow_empty_message: boolean(),
  commits: [String.t()],
  continue_pick: boolean(),
  keep_redundant_commits: boolean(),
  mainline: non_neg_integer() | nil,
  no_commit: boolean(),
  signoff: boolean(),
  skip: boolean(),
  strategy: String.t() | nil,
  strategy_option: String.t() | nil
}

Functions

args(command)

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

Returns the argument list for git cherry-pick.

When :abort, :continue_pick, or :skip is true, builds the corresponding control command. Otherwise builds the full cherry-pick command with all applicable flags and commit refs.

Examples

iex> Git.Commands.CherryPick.args(%Git.Commands.CherryPick{abort: true})
["cherry-pick", "--abort"]

iex> Git.Commands.CherryPick.args(%Git.Commands.CherryPick{continue_pick: true})
["cherry-pick", "--continue"]

iex> Git.Commands.CherryPick.args(%Git.Commands.CherryPick{skip: true})
["cherry-pick", "--skip"]

iex> Git.Commands.CherryPick.args(%Git.Commands.CherryPick{commits: ["abc123"]})
["cherry-pick", "abc123"]

iex> Git.Commands.CherryPick.args(%Git.Commands.CherryPick{commits: ["abc123"], no_commit: true})
["cherry-pick", "--no-commit", "abc123"]

parse_output(stdout, exit_code)

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

Parses the output of git cherry-pick.

For mutation operations (abort, continue, skip) with exit code 0, returns {:ok, :done}. For normal pick operations, parses into a Git.CherryPickResult struct. On failure, returns {:error, {stdout, exit_code}}.