Git Checkout and Pull through Lib2GitSharp

三世轮回 提交于 2019-12-11 13:36:23

问题


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:

// 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?


回答1:


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.



来源:https://stackoverflow.com/questions/37016540/git-checkout-and-pull-through-lib2gitsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!