Do I need to pull this branch?

One of the problems I faced during my recent work on Pumpkin was to check, whether it has to pull a new version of a repository. Using only git commands it's a nice and easy task, from C# code perspective it requires a bit more gymnastics.

Currently Pumpkin uses libgit2sharp library to communicate with each git repository so I was constrained to use its API. The first thing I thought about was to use git status command:

using (var repo = new Repository("foo/bar"))
{
    foreach (var item in repo.RetrieveStatus())
    {
    }
}

but though it gives a perfect info about status of a local repository, it doesn't touch remote. Dead end.

Another idea was to use git diff because of plenty of different overloads, which seemed to be feasible to get desired result:

using (var repo = new Repository("foo/bar"))
{
    foreach (TreeEntryChanges c in repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree,
                                                  DiffTargets.Index))
    {
    }
}

but from the performance point of view I decided, that preparing a diff and analyzing it, is not the best option, if I can find a better one.

The easiest and the best option seemed to compare SHAs of head commits from the local and the remote. It was easier than I thought:

using (var repo = new Repository("foo/bar"))
{
    var current = repo.Head.Tip.Sha;
    var remote = repo.Branches["origin/branch"].Tip.Sha;
}

With such approach I can operate on the very basic info of a repository, without a need to call additional git command.