Git.Commands.Reset (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git reset.

Supports --soft, --mixed (default), and --hard modes against any git ref (defaults to HEAD).

Summary

Functions

Returns the argument list for git reset.

Parses the output of git reset.

Types

mode()

@type mode() :: :soft | :mixed | :hard

t()

@type t() :: %Git.Commands.Reset{mode: mode(), ref: String.t()}

Functions

args(reset)

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

Returns the argument list for git reset.

Builds git reset --<mode> <ref> from the struct fields. The mode defaults to :mixed and the ref defaults to "HEAD".

Examples

iex> Git.Commands.Reset.args(%Git.Commands.Reset{})
["reset", "--mixed", "HEAD"]

iex> Git.Commands.Reset.args(%Git.Commands.Reset{mode: :soft, ref: "HEAD~1"})
["reset", "--soft", "HEAD~1"]

iex> Git.Commands.Reset.args(%Git.Commands.Reset{mode: :hard})
["reset", "--hard", "HEAD"]

parse_output(stdout, exit_code)

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

Parses the output of git reset.

On success (exit code 0), returns {:ok, :done}. On failure, returns {:error, {stdout, exit_code}}.