Git.Diff (git v0.4.0)

Copy Markdown View Source

Parsed representation of git diff output.

When used with --stat, contains a list of per-file stats. The raw field always holds the full stdout from git, regardless of whether --stat was used.

Summary

Functions

Parses the output of git diff --stat into a Git.Diff struct.

Types

t()

@type t() :: %Git.Diff{
  files: [Git.DiffFile.t()],
  raw: String.t(),
  total_deletions: non_neg_integer(),
  total_insertions: non_neg_integer()
}

Functions

parse(output)

@spec parse(String.t()) :: t()

Parses the output of git diff --stat into a Git.Diff struct.

The stat format looks like:

lib/foo.ex | 10 ++++------
lib/bar.ex |  5 +++++
2 files changed, 7 insertions(+), 5 deletions(-)

Binary files appear as:

image.png | Bin 0 -> 1234 bytes

The summary line is used for total_insertions and total_deletions. If the output is a full patch (no --stat), the files list will be empty and raw will contain the patch text.

Examples

iex> output = " foo.ex | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n"
iex> diff = Git.Diff.parse(output)
iex> diff.total_insertions
1