Git.Commands.DiffTree (git v0.7.0)

Copy Markdown View Source

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

Compares the content and mode of blobs found via two tree-ish arguments, or (with a single tree-ish) a commit against its first parent. Output is requested with --raw -z and parsed into Git.DiffRawEntry structs.

Summary

Functions

Returns the argument list for git diff-tree.

Parses the output of git diff-tree --raw -z.

Types

t()

@type t() :: %Git.Commands.DiffTree{
  find_renames: boolean(),
  recursive: boolean(),
  tree_ish: String.t(),
  tree_ish2: String.t() | nil
}

Functions

args(command)

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

Returns the argument list for git diff-tree.

Options:

  • :tree_ish - the first (or only) tree-ish to diff (default "HEAD")
  • :tree_ish2 - a second tree-ish; when set, diffs tree_ish tree_ish2
  • :recursive - adds -r to recurse into subtrees (default false)
  • :find_renames - adds -M to detect renames (default false)

Examples

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

iex> Git.Commands.DiffTree.args(%Git.Commands.DiffTree{recursive: true})
["diff-tree", "--raw", "-z", "-r", "HEAD"]

iex> Git.Commands.DiffTree.args(%Git.Commands.DiffTree{tree_ish: "HEAD~1", tree_ish2: "HEAD", recursive: true})
["diff-tree", "--raw", "-z", "-r", "HEAD~1", "HEAD"]

iex> Git.Commands.DiffTree.args(%Git.Commands.DiffTree{find_renames: true, recursive: true})
["diff-tree", "--raw", "-z", "-r", "-M", "HEAD"]

parse_output(stdout, exit_code)

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

Parses the output of git diff-tree --raw -z.

On success (exit code 0), returns {:ok, [Git.DiffRawEntry.t()]}. On failure, returns {:error, {stdout, exit_code}}.