0

Trying to clone a remote repository using LibGit2Sharp v.0.18.1.0 throws this exception:

LibGit2Sharp.LibGit2SharpException: Failed to mmap. Invalid handle value: The volume for a file has been externally altered so that the opened file is no longer valid.

at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)

Using the same url and workdir, I have successfully cloned the repository both using Git Bash and SourceTree. But for my task I need to do it programatically, and LibGit2Sharp seemed like a good choice.

Update: Somehow the error changed, now I get around 20KB of the remote repository and then this error:

A first chance exception of type 'System.AccessViolationException' occurred in LibGit2Sharp.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Update 2: The AccessViolationException was caused by a different cause (trying to clone with an emtpy string as remote url!)

Kayak58
  • 41
  • 7
  • Please file an issue in the **[issue tracker](https://github.com/libgit2/libgit2sharp/issues/new)**. We'll happily take a look at it. – nulltoken Aug 19 '14 at 12:10
  • @kayak58 I am facing almost exactly the same error as you are when running the GitVersion application against my repository which is stored in Stash. Unfortunately, my repo is private, and I can't share it with the public. Is it possible that your repo is public? That way the maintainers of LibGit2Sharp might be able to take a look and see what is going on? – Gary Ewan Park Aug 20 '14 at 07:57
  • Issue created: [#794](https://github.com/libgit2/libgit2sharp/issues/794) – Kayak58 Aug 20 '14 at 08:06
  • @Gary: Unfortunately I'm accessing a private repo on Stash as well, but I might convince the owners to make public repo for test. – Kayak58 Aug 20 '14 at 08:09
  • @kayak58, if you could that would be great. I unfortunately don't have that luxury :-( Interesting that we are both running Stash. Which version of Stash are you using? – Gary Ewan Park Aug 20 '14 at 08:22
  • nulltoken has created a temporary fix for this problem: [https://github.com/libgit2/libgit2sharp/issues/794#issuecomment-52778189](https://github.com/libgit2/libgit2sharp/issues/794#issuecomment-52778189) – Kayak58 Aug 21 '14 at 11:17

1 Answers1

0

TL;DR

This is an issue with LibGit2Sharp v0.18.1. This will be fixed in the upcoming v0.19 (See PR #798).

More detailed information

It looks like Stash sends empty packets to keep the connection alive while the repository is being fetched. The embedded version of libgit2 in LibGit2Sharp v0.18.1 was thus trying to map a zero length file, causing the error.

It's been fixed meanwhile in libgit2 with commit libgit2/libgit2@bc8a08868.

Update

The Pull Request has been merged and the issue is fixed in the now released LibGit2Sharp v0.19. This issue should no longer happen.

Community
  • 1
  • 1
nulltoken
  • 64,429
  • 20
  • 138
  • 130