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
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:name_only— adds--name-onlyfor listing just file paths:name_status— adds--name-statusfor file paths with status letters: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{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}}.