How to get git branch information about each of commit by using 'LibGit2sharp'

Viewed 353

I'd like to make 'Commit History Graph' by using libgit2sharp library like below.

enter image description here

There was a similar question in stackoverflow, but I couldn't get the specific answer.


Here is my source code.

string path = "c:\github\git-gui-app";
var repo = Repository(path);
var commits = repo.Commits();
var list = new List<CommitItem>();
foreach (var item in commits)
{
    var commitItem = new CommitItem();
    commitItem.Name = item.Message;
    commitItem.Sha = item.Sha;
    commitItem.ParentSha = item.Parents.FirstOrDefault().Sha;
    list.Add(commitItem);
}
foreach (var item in list)
{
    item.BranchInfo = GetBranchInfo(item);
}

...

private BranchItem GetBranchInfo(CommitItem item)
{
    // How to get branch information in current commit?
}

I succeeded in getting the git repository commit information, but I still don't know how to get branch information of each commit.

0 Answers
Related