Git.Commands.DiffIndex (git v0.6.1)

Copy Markdown View Source

Implements the Git.Command behaviour for git diff-index.

Compares a tree-ish to the index and the working tree (or, with :cached, to the index only). Output is requested with --raw -z and parsed into Git.DiffRawEntry structs.

With :quiet the command runs as a dirty-check: git exits 1 when there are differences, which is treated as a signal rather than an error. In that mode the wrapper returns a boolean instead of a list of entries.

Summary

Functions

Returns the argument list for git diff-index.

Parses the output of git diff-index.

Types

t()

@type t() :: %Git.Commands.DiffIndex{
  cached: boolean(),
  quiet: boolean(),
  tree_ish: String.t()
}

Functions

args(command)

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

Returns the argument list for git diff-index.

Options:

  • :tree_ish - the tree-ish to compare against (default "HEAD")
  • :cached - adds --cached to compare against the index only
  • :quiet - adds --quiet for a dirty-check (exit 1 = differences)

Examples

iex> Git.Commands.DiffIndex.args(%Git.Commands.DiffIndex{})
["diff-index", "--raw", "-z", "HEAD"]

iex> Git.Commands.DiffIndex.args(%Git.Commands.DiffIndex{cached: true})
["diff-index", "--raw", "-z", "--cached", "HEAD"]

iex> Git.Commands.DiffIndex.args(%Git.Commands.DiffIndex{quiet: true})
["diff-index", "--quiet", "HEAD"]

parse_output(stdout, exit_code)

@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, [Git.DiffRawEntry.t()] | boolean()}
  | {:error, {String.t(), non_neg_integer()}}

Parses the output of git diff-index.

In raw mode (the default), returns {:ok, [Git.DiffRawEntry.t()]} on exit code 0 and {:error, {stdout, exit_code}} otherwise.

In quiet mode, exit code 0 means no differences ({:ok, false}) and exit code 1 means differences were found ({:ok, true}). Any other exit code is a real git error and returns {:error, {stdout, exit_code}}.