3

I'm looking for a way to capture how many lines have changed in each file in my working directory - like git diff --stat in git - is there a way to do this with LibGit2Sharp?

I know I can get total LinesAdded/Deleted from a Patch, but I'm wondering on a file by file basis.

sorrell
  • 1,801
  • 1
  • 16
  • 27

1 Answers1

6

The following will enumerate all the files that have been changed between two commits, along with the number of changes (global, line additions and line removals).

var patch = repo.Diff.Compare<Patch>(fromCommit, untilCommit);

foreach (var pec in patch)
{
    Console.WriteLine("{0} = {1} ({2}+ and {3}-)",
        pec.Path,
        pec.LinesAdded + pec.LinesDeleted,
        pec.LinesAdded,
        pec.LinesDeleted);
}

Would you need to access a specific file within a Patch, the types exposes an indexer to ease that

PatchEntryChanges entryChanges = patch["path/to/my/file.txt"];
nulltoken
  • 64,429
  • 20
  • 138
  • 130