Badgerspot
Badgerspot

Reputation: 2491

How do I get "git log --name-only" in libgit2

In GitBash git log --name-only -1 gives me:

commit e584beed88a9d005e7066c41b248545ae99f6c2b    
Author: Badgers Paw < [email protected] >    
Date:   Thu Dec 1 13:39:03 2016 +0000    
    EEE-9245 - WIP
Components/BuildTools/BuildTasks.Test/Class1.cs
Components/BuildTools/BuildTasks.exe
Components/BuildTools/BuildTasks/Docs/README.txt
Components/BuildTools/BuildTasks/Program.cs
Components/BuildTools/BuildTasks/Tasks/Task1.cs
Components/BuildTools/BuildTasks/Tasks/Task2.cs

How can I get this in libgit2 or (ideally) libgit2sharp?

Thanks

Upvotes: 0

Views: 465

Answers (2)

Badgerspot
Badgerspot

Reputation: 2491

Using libgit2sharp this is:

var parent = commit.Parents.Single();
{
    foreach (TreeEntryChanges change in repo.Diff.Compare<TreeChanges>(parent.Tree, commit.Tree))
        {
            Debug.WriteLine(change.Path);
        }
    }
}

Upvotes: 0

Jason Haslam
Jason Haslam

Reputation: 2897

You have to run a diff to get the list of changed files. For the first log entry it would be git_diff_tree_to_tree between the HEAD commit and it's parent. After you run the diff you can ignore the rest of the information and print the name of the files only.

Upvotes: 2

Related Questions