1

I'm trying to clone a git repository using Repository.Clone.

Here's an example piece of code used for the clone command.

public string Clone(string remoteRepository, string path, string username, string password)
{
    string myPassword;
    CloneOptions options = new CloneOptions();
    options.CredentialsProvider = (url, user, cred) =>
    {
        return new UsernamePasswordCredentials {Username = username, Password = password};
    };
    return Repository.Clone(remoteRepository, path, options);
}

The code works fine on some repositories, but for others I get the exception

Here's the exception that I'm getting

{"Failed to stat file 'snipped': The filename or extension is too long.\r\n"}

The "snipped" path in it's entirety is 270 characters long. So I know that this is falling foul of the extremely old MAX_PATH rule.

According to some of the windows documentation, you can use unicode paths by adding \?\ to the start of the path which will allow long paths to be used with windows API calls. However this isn't working for LibGit2Sharp.

Is there a way of supplying a setting to LibGit2Sharp to allow it to work with long paths? Or failing that, is there an alternative nuget package that will allow this behaviour?

Colin Dawson
  • 435
  • 2
  • 12

1 Answers1

1

Add this to App.manifest which would allow long paths. I tried using /?// and unc both didn't help much. But this worked.

<windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
    <ws2:longPathAware>true</ws2:longPathAware>
  </windowsSettings>
Prajwal
  • 3,930
  • 5
  • 24
  • 50