Implements the Git.Command behaviour for git diff.
Supports working-tree diffs, staged (cached) diffs, stat-only output, comparing against a specific ref, and limiting to a path.
Summary
Types
@type t() :: %Git.Commands.Diff{ diff_filter: String.t() | nil, find_copies: boolean(), find_renames: boolean(), ignore_all_space: boolean(), ignore_space_at_eol: boolean(), ignore_space_change: boolean(), name_only: boolean(), name_status: boolean(), numstat: boolean(), path: String.t() | nil, ref: String.t() | nil, ref_end: String.t() | nil, reverse: boolean(), staged: boolean(), stat: boolean(), unified: non_neg_integer() | nil }
Functions
Returns the argument list for git diff.
Options:
:staged— adds--cachedto show staged changes:stat— adds--statfor file-level summary instead of full patch:numstat— adds--numstatfor machine-readable per-file insertion and deletion counts (parsed intofileswith exact counts):name_only— adds--name-onlyfor listing just file paths:name_status— adds--name-statusfor file paths with status letters:ignore_all_space— adds-w:ignore_space_change— adds-b:ignore_space_at_eol— adds--ignore-space-at-eol:find_renames— adds-M:find_copies— adds-C:reverse— adds-Rto swap the two sides:unified— adds-U<n>to set the number of context lines:diff_filter— adds--diff-filter=<value>(e.g."ACMR"):ref— adds a ref to compare against (e.g.,"HEAD~1"):ref_end— when set with:ref, comparesref ref_end(two-ref diff):path— adds-- <path>to limit the diff
Examples
iex> Git.Commands.Diff.args(%Git.Commands.Diff{})
["diff"]
iex> Git.Commands.Diff.args(%Git.Commands.Diff{staged: true, stat: true})
["diff", "--cached", "--stat"]
iex> Git.Commands.Diff.args(%Git.Commands.Diff{numstat: true, ignore_all_space: true})
["diff", "--numstat", "-w"]
iex> Git.Commands.Diff.args(%Git.Commands.Diff{find_renames: true, unified: 0})
["diff", "-M", "-U0"]
iex> Git.Commands.Diff.args(%Git.Commands.Diff{ref: "HEAD~1", path: "lib/"})
["diff", "HEAD~1", "--", "lib/"]
@spec parse_output(String.t(), non_neg_integer()) :: {:ok, Git.Diff.t()} | {:error, {String.t(), non_neg_integer()}}
Parses the output of git diff.
On success (exit code 0), returns {:ok, %Git.Diff{}}.
On failure, returns {:error, {stdout, exit_code}}.