libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

Repository.Clone fails with "Filename too long" error

Open panuganti opened this issue 7 years ago • 21 comments

My attempt to use Repository.Clone fails with the error.. LibGit2Sharp.NameConflictException: Failed to stat file '<..some long path..>': The filename or extension is too long.

Is there any solution for this ? I believe, I need to set core.longpaths in the global config to true. Is there anyway to do that ?

panuganti avatar Oct 03 '16 23:10 panuganti

core.longpaths is something that's specific to the Git for Windows distribution of git. libgit2 does not support it, and neither does most of Windows.

carlosmn avatar Oct 05 '16 09:10 carlosmn

So, what is the solution to this problem ? Setting global config should be supported by LibGit2Sharp. Is there a way ?

panuganti avatar Oct 05 '16 17:10 panuganti

You must try using Long Path Tool. This tool enables you to rename, delete, or move the file easily. I have used it multiple times and it works perfectly.

Stepan222 avatar Oct 24 '16 07:10 Stepan222

Any update on this problem?

klyse avatar Feb 06 '18 15:02 klyse

Any update on this problem?

Nope! Still fails (just like 99% of all Windows applications)

ethomson avatar Feb 06 '18 16:02 ethomson

Maybe you will be this 1% ;)

coderitual avatar Mar 16 '18 10:03 coderitual

I have now successfully circumvented the problem in Windows 10 by disabling the 260 character limit on NTFS (see below). Setting git config --system core.longpaths true did not work for (still set it anyways). I have altered the group policy as per this post (quote the relevant part here):

Since Windows 10 there's another option by removing MAX_PATH limitation§. You can enable it by setting HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled in registry or set Computer Configuration > Administrative Templates > System > Filesystem > Enable NTFS long paths in group policy

Edit: My problem was with opening the repository, not necessarily with cloning it. I had it previously cloned with git clone -c core.longpaths=true https://github.com/apache/hadoop.git and then opened it with libgit2sharp

MrShoenel avatar Feb 22 '19 12:02 MrShoenel

I have this problem when trying to use GitVersion with teamcity. When using a build in teamcity with the windows git client checking out repos with long paths enabled in git configs, works fine. However, I cannot fix it for GitVersion or more specifically the referenced libgit2sharp libraries. I even built a 2016 svr to run a Teamcity agent on and set git config --system core.longpaths true as our teamcity build server runs on 2012 R2 Server. I also set the policy to enable on the 2016 server with the TeamCity agent as @MrShoenel did above. This library is used by gitversion and on windows it breaks ,this must be fixable, would be happy to do it if someone can point me in the right direction... (And btw I cannot reduce longpaths in the VS solutions as it is a website with tons of node modules... ). lastly when I run git version against an already cloned local copy on windows 10 it works fine. Any pointers to finding a fix or work around to this would be greatly appreciated :)

andrew-allen-work avatar Apr 23 '19 18:04 andrew-allen-work

So sorry to mention this issue again. But I have to. I used libgit2sharp in my project. When users try to break 260 character limit, error throws. When I use win10&vscode&git as develop envirenment, it can do work well. And my project is base on dotnet-core-2.0 , it can do well on 260 or more characters as creating folders/files. My english is not good, and i hope i have made myself clear.

MrLiu0635 avatar Mar 31 '20 09:03 MrLiu0635

I'm wondering why this issue is closed. On windows 10 with no longpath settings what so ever: Cloning from gitbash / git for windows - no problem. Cloning from VS - no problem Cloning with libgit2sharp - big problem

noontz avatar May 19 '20 11:05 noontz

I would love to know also :-)

andrew-allen-work avatar May 19 '20 12:05 andrew-allen-work

I'm wondering why this issue is closed.

It's not.

Screen Shot 2020-05-19 at 14 57 30

ethomson avatar May 19 '20 13:05 ethomson

@ethomson UPPS.... Sorry...

noontz avatar May 20 '20 12:05 noontz

No problem! Sorry this is such a thorny problem. There's been some work started in libgit2 to address it.

ethomson avatar May 20 '20 19:05 ethomson

Is there any ETA for the fix to this issue?

smoczas avatar Jul 07 '20 10:07 smoczas

@carlosmn worst attitude. "bla bla windows sucks", guess what git works just fine if "git config --system core.longpaths true" What is the issue in libgit2sharp ? Why is it different ? Can git2sharp support it ?

alinmircea avatar Jul 20 '20 23:07 alinmircea

Nodegit (which also binds to libgit2) release v26.5 was released in March and included the merged PR #5347 supporting this although this is not yet merged to master in libgit2. See: https://github.com/nodegit/nodegit/pull/1748

Is this an option for libgit2sharp?

Lack of support for this is becoming increasingly a problem with various project package components (including node_modules) and testing frameworks with deep descriptive paths unable to be consumed.

rupreck avatar Oct 14 '20 09:10 rupreck

Try using with CloneOptions with flag IsBare = true. This solved the issue for me.

Solairw avatar Mar 12 '21 02:03 Solairw

Try using with CloneOptions with flag IsBare = true. This solved the issue for me.

This alone makes the output zip file unusable as it is saved in an encrypted Git format. Do you have any other changes that you made with this that maybe prevented this issue?

DewaldNel avatar Oct 19 '21 14:10 DewaldNel

Looks core.longpaths are supported since libgit2 v1.2.0. Is there any blocking point to support it in libgit2sharp?

sulkowsj avatar Jan 11 '22 17:01 sulkowsj

Any update?

dcworldwide avatar Sep 16 '22 04:09 dcworldwide