Git Checkout and Pull through Lib2GitSharp

I am trying to build an application that periodically scans the commit history on various Git branches and reports on the authors and various details about the commit messages. I have started using LibGit2Sharp for this. It has been great for accessing the commits themselves, but I have run into a snag when trying to update the repository.

Every time my task runs, I need to get the most recent changes from the remote repository. My understanding is I need to checkout the local branch that tracks the remote branch in question, then perform a fetch or pull. I am attempting to do this in my app as follows:

  • Looping through every commit in Git repository with LibGit2Sharp?
  • Git/SSH hanging when called from MVC WebApi
  • git and C++ workflow, how to handle object and archive files?
  • Query Git programmatically in Visual Studio
  • Nuget fails to manage references in a project cloned from git
  • How to keep change history while renaming files in Visual Studio using Perforce
  • // Get the branch
    var localBranch = repo.Branches[localbranchName];
    
    // Switch to this branch
    if (!localBranch.IsCurrentRepositoryHead)
    {
        repo.Checkout(localBranch);
    }
    
    // Do a pull to get latest
    var result = repo.Network.Pull(signature, new PullOptions());
    

    However, I always get the following exception when running repo.Checkout(localBranch);

    LibGit2Sharp.LibGit2SharpException: Failed to mmap. No data written: Not enough storage is available to process this command.
      at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in c:\Git\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 160
      at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in c:\Git\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 178
      at LibGit2Sharp.Core.Proxy.git_checkout_tree(RepositorySafeHandle repo, ObjectId treeId, GitCheckoutOpts& opts) in c:\Git\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 295
      at LibGit2Sharp.Repository.CheckoutTree(Tree tree, IList`1 paths, IConvertableToGitCheckoutOpts opts)...
    

    When I manually checkout that branch in Git Bash and run my program (bypassing the need for the the checkout command) it then fails on the call to Pull with the same exception.

    There’s not a whole lot about this error out there but everything I’ve seen so far has resulted in answers to the extent of “Your repository is just too large for the library to handle.” The repository I am using is a fair-sized enterprise repository, but these commands execute in the console pretty quickly. I’m wondering now if I need to wrap my console in a handler and execute the checkout and pull directly through the CLI (yuck).

    Any thoughts?

  • Remove sensitive configuration data from commit history
  • ssh config not working. Permission denied (publickey)
  • Git rebasing interactive not squashing when fast forward available
  • How can I deploy direct from Google Cloud Source Repository to Google App Engine?
  • My pull request has been merged, what to do next?
  • I can't see my project in gitweb. How do you configure gitweb properly?
  • One Solution collect form web for “Git Checkout and Pull through Lib2GitSharp”

    Apologies for this. There have been a handful of changes to libgit2 and LibGit2Sharp to deal with memory usage, and better handling of memory mapping, especially with large (or numerous) packfiles.

    You will see these improvements in the next release of LibGit2Sharp. Until then, installing a prerelease package from nuget.org should resolve this issue.

    Git Baby is a git and github fan, let's start git clone.