Git.Commands.Revert (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git revert.

Supports reverting one or more commits, aborting an in-progress revert, continuing after conflict resolution, and skipping a commit during a multi-commit revert.

Summary

Functions

Returns the argument list for git revert.

Parses the output of git revert.

Types

t()

@type t() :: %Git.Commands.Revert{
  abort: boolean(),
  commits: [String.t()],
  continue_revert: boolean(),
  mainline: non_neg_integer() | nil,
  no_commit: boolean(),
  no_edit: 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 revert.

  • When :abort is true, builds git revert --abort.
  • When :continue_revert is true, builds git revert --continue.
  • When :skip is true, builds git revert --skip.
  • Otherwise builds git revert [options] <commits>.

Examples

iex> Git.Commands.Revert.args(%Git.Commands.Revert{commits: ["HEAD"]})
["revert", "HEAD"]

iex> Git.Commands.Revert.args(%Git.Commands.Revert{commits: ["HEAD"], no_commit: true})
["revert", "--no-commit", "HEAD"]

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

iex> Git.Commands.Revert.args(%Git.Commands.Revert{continue_revert: true})
["revert", "--continue"]

iex> Git.Commands.Revert.args(%Git.Commands.Revert{skip: true})
["revert", "--skip"]

parse_output(stdout, exit_code)

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

Parses the output of git revert.

For --abort, --continue, and --skip operations (exit code 0), returns {:ok, :done}. For normal revert operations (exit code 0), parses into a Git.RevertResult struct. On failure, returns {:error, {stdout, exit_code}}.