Git.Commands.Reset (git v0.6.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git reset.

Supports two forms:

  • whole-tree reset, git reset --<mode> <ref>, with :mode one of :soft, :mixed (default), :hard, :merge, or :keep
  • pathspec reset, git reset <ref> -- <paths>, selected by giving :files. This unstages the listed paths; :mode does not apply to this form (git rejects a mode flag together with a pathspec).

Summary

Functions

Returns the argument list for git reset.

Parses the output of git reset.

Types

mode()

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

t()

@type t() :: %Git.Commands.Reset{
  files: [String.t()],
  mode: mode(),
  quiet: boolean(),
  ref: String.t()
}

Functions

args(reset)

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

Returns the argument list for git reset.

With :files, builds the pathspec form git reset [-q] <ref> -- <paths>. Otherwise builds the whole-tree form git reset --<mode> [-q] <ref>. 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"]

iex> Git.Commands.Reset.args(%Git.Commands.Reset{files: ["a.ex", "b.ex"]})
["reset", "HEAD", "--", "a.ex", "b.ex"]

iex> Git.Commands.Reset.args(%Git.Commands.Reset{mode: :keep, quiet: true})
["reset", "--keep", "-q", "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}}.