LibGit2Sharp Find which files have been updated / added / removed after clicking

After running the command, repo.Network.Pull()

I want to see which files have been added to the repository, changed in the repository, and removed from the repository. All I need is the path to the file file and if it was add / update or remove.

Is there an easy way to do this? I've tried looking in Diff.Compare()

, but I'm not sure if this is the correct way to do it.

+3


source to share


1 answer


LibGit2Sharp 0.21.0.176

Here is a libGit2 example to walk through your current commit tree and get the files that have changed and the type of change.

Git version:

git log --name-status --pretty=oneline

1d9d4bb881f97f5d3b67741a893f238e7221e2b1 Updated readme with fork info
M       README.md
58cc5c41963d5ff68556476158c9c0c2499e061c Update Makefile for PE32+ (platform:x64) assemblies
M       Makefile
M       README.md
a7823c1c0a737c5218d33691f98828c78d52130b Fix Makefile for 64-bit native lib and add README.md
M       Makefile
A       README.md
ea7e6722f67569cb9d7a433ff2c036fc630d8561 Update solution files.
M       mono-curses.csproj
M       mono-curses.sln
05dbe6e18895d1037ce333b0a1f652eeae3f8b33 Fix resize handling.
M       attrib.c
M       gui.cs

      

libGit2 version:



    var repo = new LibGit2Sharp.Repository ("/your/repo/path");
    foreach (Commit commit in repo.Commits) {
        foreach (var parent in commit.Parents) {
            Console.WriteLine ("{0} | {1}", commit.Sha, commit.MessageShort);
            foreach (TreeEntryChanges change in repo.Diff.Compare<TreeChanges>(parent.Tree,
            commit.Tree)) {
                Console.WriteLine ("{0} : {1}", change.Status, change.Path);
            }
        }
    }

      

Output:

1d9d4bb881f97f5d3b67741a893f238e7221e2b1 | Updated readme with fork info
Modified : README.md
58cc5c41963d5ff68556476158c9c0c2499e061c | Update Makefile for PE32+ (platform:x64) assemblies
Modified : Makefile
Modified : README.md
a7823c1c0a737c5218d33691f98828c78d52130b | Fix Makefile for 64-bit native lib and add README.md
Modified : Makefile
Added : README.md
ea7e6722f67569cb9d7a433ff2c036fc630d8561 | Update solution files.
Modified : mono-curses.csproj
Modified : mono-curses.sln
05dbe6e18895d1037ce333b0a1f652eeae3f8b33 | Fix resize handling.
Modified : attrib.c
Modified : gui.cs

      

In a straight forward answer to your question, just take the first commit from the Commits enumerator and compare its tree with the parents (there may be more than one parent due to the merge) versus my example of a cycle of all commits in the current branch.

+2


source







All Articles