libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

Repository.Init and Repository.Clone fail with path too long

Open pde-cds opened this issue 2 years ago • 7 comments

Reproduction steps

Set core.longpaths = true in global or user Use either Repository.Init or Repository.Clone on a path which is longer than 260

Expected behavior

Init and Clone work without an error

Actual behavior

LibGit2Sharp.Exception (path too long)

Version of LibGit2Sharp (release number or SHA1)

0.27.2

Operating system(s) tested; .NET runtime tested

Win 10 22H2 (.NET 4.8)

pde-cds avatar Jul 19 '23 09:07 pde-cds

This behaviour can reproduced via UnitTest

    [Theory]
    [InlineData("http://github.com/libgit2/TestGitRepository")]
    [InlineData("https://github.com/libgit2/TestGitRepository")]
    public void CanCloneLongPath(string url)
    {
        var scd = BuildSelfCleaningDirectory();

        string firstFolder = new string('a', 100);
        string secondFolder = new string('b', 200);
        string sPath = Path.GetFullPath(Path.Combine(".", firstFolder, secondFolder));

        string clonedRepoPath = Repository.Clone(url, sPath);
   }

This will fail with an LibGit2SharpException path too long

pde-cds avatar Jul 19 '23 12:07 pde-cds

Is there any sensible solution? It is impossible to use the package with such a blocking error. Version 0.28.0 - all the same

kazakevich-alexei avatar Nov 09 '23 10:11 kazakevich-alexei

Only after execution «git config --system core.longpaths true» It's starting to work.

kazakevich-alexei avatar Nov 09 '23 10:11 kazakevich-alexei

@kazakevich-alexei The setting you mentioned works only for longpaths inside a repository. A repository which will be created in a longpath still does not work

pde-cds avatar Nov 13 '23 08:11 pde-cds

Have the same issue here. :(

LibGit2Sharp.Repository.Clone(repo.CloneUrl, clonedRepoPath, branchCloneOptions);

When I oull out libGit2SharpException.Message I getting this: path too long: 'D:/Backup data/GitHub/Github Backup 08-03-2024-(11-46)/michaelmsonne/xxxxxxxxxx/code/main/xxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxx/xxxxxxxxxxxx/xxxxxxxxxxx.ps1'

Total path is 273 for one sample here from a console application.

Regedit longpath is set, AppContext.SetSwitch("System.IO.UseLegacyPathHandling", false); is set too and so - same issues..

michaelmsonne avatar Mar 08 '24 11:03 michaelmsonne

@michaelmsonne git supports long paths only when the core.longpaths is set as a configuration option. There's a bootstrapping problem here, which is that you don't have a config during a clone.

More information is here. https://github.com/libgit2/libgit2/blob/9903482593db438abbbbaf5324a0cc78c5472603/docs/win32-longpaths.md

What does git do in this case?

ethomson avatar Mar 08 '24 11:03 ethomson

@ethomson thanks - I found that too after i posted it..

I have a .Net Console Apllication (portable) there is using this to backup repos to a local path on a Windows Server.

The "core.longpaths" - how can I in some way "setup" this so the application is working when moved around (as it is portale)? 🤔

michaelmsonne avatar Mar 08 '24 11:03 michaelmsonne