libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.12k stars 878 forks source link

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

Open pde-cds opened 11 months ago

pde-cds commented 11 months ago

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 commented 11 months ago

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

kazakevich-alexei commented 8 months ago

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 commented 8 months ago

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

pde-cds commented 7 months ago

@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

michaelmsonne commented 4 months ago

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..

ethomson commented 4 months ago

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

michaelmsonne commented 4 months ago

@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)? 🤔