Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pde-cds opened this issue Jul 19, 2023 · 7 comments
Open

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

pde-cds opened this issue Jul 19, 2023 · 7 comments

Comments

@pde-cds
Copy link

pde-cds commented Jul 19, 2023

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
Copy link
Author

pde-cds commented Jul 19, 2023

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
Copy link

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
Copy link

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

@pde-cds
Copy link
Author

pde-cds commented Nov 13, 2023

@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
Copy link

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
Copy link
Member

ethomson commented Mar 8, 2024

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants