Skip to content

AheadBehind compare two local branches #562

Closed
@Aimeast

Description

@Aimeast

To calculate AheadBehind with two local branches.

My application level code is

using (var repo = new Repository(@"\libgit2sharp"))
{
    var head = repo.Head;
    var branch = repo.Branches["vNext"];

    var commitLog = repo.Commits;
    var commonAncestor = commitLog.FindCommonAncestor(head.Tip, branch.Tip);
    var ahead = commitLog.QueryBy(new CommitFilter { Since = branch.Tip, Until = commonAncestor });
    var behind = commitLog.QueryBy(new CommitFilter { Since = head.Tip, Until = commonAncestor });

    var Ahead = ahead.Count();
    var Behind = behind.Count();
}

But it very slowly and the result not very equals to github. It is available in libgit2?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions