libgit2 / libgit2sharp

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

Invalid Path on Long File Paths for .net applications with long path support #1805

Open MarkAtRamp51 opened 4 years ago

MarkAtRamp51 commented 4 years ago

Reproduction steps

On Windows 10 (or any windows OS that supports long file paths, with Enable Win32 Long Paths enabled) Create a file path more than 260 characters long

Create a .net application using a version of .net framework of 4.6.2 or newer, and add an application manifest to enables support for long file paths. Call the Commands.Stage on this repo, adding all files.

An invalid path exception will be thrown indicating the path is too long.

Running "git add ." from the command line works as long as the core.longpaths=true config option is set in git, but the .net application still fails with this exception.

The system gitconfig looks as follows:

[diff "astextplain"]
    textconv = astextplain
[filter "lfs"]
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
    required = true
[http]
    sslBackend = schannel
[core]
    autocrlf = true
    symlinks = false
    longpaths = true
[pull]
    rebase = false

Expected behavior

Commands.Stage should add all the files to the index, as long as the file paths are less than 4096 characters.

Actual behavior

An InvalidPath exception is thrown:

Error: LibGit2Sharp.LibGit2SharpException: invalid path '\\?\C:\REPLACE WITH REALLY LONG FOLDER PATH AND FILE NAME.xml' (path too long)
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 136
   at LibGit2Sharp.Core.Proxy.git_diff_index_to_workdir(RepositoryHandle repo, IndexHandle index, GitDiffOptions options) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 809
   at LibGit2Sharp.Diff.<>c__DisplayClass28_0.<WorkdirToIndex>b__0(ObjectId oh, ObjectId nh, GitDiffOptions o) in C:\projects\libgit2sharp\LibGit2Sharp\Diff.cs:line 506
   at LibGit2Sharp.Diff.BuildDiffList(ObjectId oldTreeId, ObjectId newTreeId, TreeComparisonHandleRetriever comparisonHandleRetriever, DiffModifiers diffOptions, IEnumerable`1 paths, ExplicitPathsOptions explicitPathsOptions, CompareOptions compareOptions) in C:\projects\libgit2sharp\LibGit2Sharp\Diff.cs:line 561
   at LibGit2Sharp.Diff.Compare[T](DiffModifiers diffOptions, IEnumerable`1 paths, ExplicitPathsOptions explicitPathsOptions, CompareOptions compareOptions) in C:\projects\libgit2sharp\LibGit2Sharp\Diff.cs:line 484
   at LibGit2Sharp.Commands.Stage(IRepository repository, IEnumerable`1 paths, StageOptions stageOptions) in C:\projects\libgit2sharp\LibGit2Sharp\Commands\Stage.cs:line 77
   at LibGit2Sharp.Commands.Stage(IRepository repository, String path) in C:\projects\libgit2sharp\LibGit2Sharp\Commands\Stage.cs:line 25
   at AppMethodCall() in C:\....\GitRepository.cs:line 118

Version of LibGit2Sharp (release number or SHA1)

0.26.2.97

Operating system(s) tested; .NET runtime tested

Windows Server 2019 Datacenter Edition, .NET Framework 4.7.2

MarkAtRamp51 commented 4 years ago

Actually I noticed that this isn't supported by libgit2 yet, but there is a pending pull request for it so it may come soon.

japj commented 4 years ago

This is probably also related/duplicate of the underlying problem in #1374 @MarkAtRamp51 what was the PR number? I can't seem to find a current PR related to long path support

MarkAtRamp51 commented 4 years ago

@japj It's this one https://github.com/libgit2/libgit2/pull/5347

phatcher commented 2 years ago

This has been patched in lib2git as of release 1.2, and the LibGit2Sharp.NativeBinaries has been update to point at 1.3 so this should work now, so if the dependency is changed from 2.0.315-alpha.0.1 to 2.0.315-alpha.0.4 we should be ok.

DenisKudelin commented 2 months ago

Fix https://github.com/libgit2/libgit2sharp/pull/2120