Skip to content

Commit da38351

Browse files
author
Denis Kudelin
committed
Add support for long file paths in CheckoutOptions
1 parent 5085a0c commit da38351

File tree

8 files changed

+63
-1
lines changed

8 files changed

+63
-1
lines changed

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,5 +601,30 @@ public void CanCloneWithCustomHeaders()
601601
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, cloneOptions);
602602
Assert.True(Directory.Exists(clonedRepoPath));
603603
}
604+
605+
[Fact]
606+
public void CanCloneWithLongPaths()
607+
{
608+
var scd = BuildSelfCleaningDirectory();
609+
610+
var cloneOptions = new CloneOptions
611+
{
612+
LongPaths = true
613+
};
614+
615+
string clonedRepoPath = Repository.Clone("https://github.com/luiswolff/test-long-file-path.git", scd.DirectoryPath, cloneOptions);
616+
617+
using (var repo = new Repository(clonedRepoPath))
618+
{
619+
string dir = repo.Info.Path;
620+
Assert.True(Path.IsPathRooted(dir));
621+
Assert.True(Directory.Exists(dir));
622+
Assert.NotNull(repo.Info.WorkingDirectory);
623+
Assert.Equal(Path.Combine(scd.RootedDirectoryPath, ".git" + Path.DirectorySeparatorChar), repo.Info.Path);
624+
Assert.False(repo.Info.IsBare);
625+
626+
// Add additional assertions if necessary to verify long path support
627+
}
628+
}
604629
}
605630
}

LibGit2Sharp/CheckoutOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public sealed class CheckoutOptions : IConvertableToGitCheckoutOpts
3030
/// controlled with the CheckoutNotifyFlags property.
3131
public CheckoutProgressHandler OnCheckoutProgress { get; set; }
3232

33+
/// <inheritdoc />
34+
public bool LongPaths { get; set; }
35+
3336
CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
3437
{
3538
get

LibGit2Sharp/CloneOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public CloneOptions()
2121
/// </summary>
2222
public bool IsBare { get; set; }
2323

24+
/// <inheritdoc />
25+
public bool LongPaths { get; set; }
26+
2427
/// <summary>
2528
/// If true, the origin's HEAD will be checked out. This only applies
2629
/// to non-bare repositories.

LibGit2Sharp/Core/GitCheckoutOpts.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ internal enum CheckoutStrategy
105105
/// </summary>
106106
GIT_CHECKOUT_DONT_WRITE_INDEX = (1 << 23),
107107

108+
/// <summary>
109+
/// Support for long file paths.
110+
/// </summary>
111+
GIT_CHECKOUT_LONGPATHS = (1 << 24),
112+
108113
// THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
109114

110115
/// <summary>
@@ -183,6 +188,11 @@ internal interface IConvertableToGitCheckoutOpts
183188
CheckoutStrategy CheckoutStrategy { get; }
184189

185190
CheckoutNotifyFlags CheckoutNotifyFlags { get; }
191+
192+
/// <summary>
193+
/// True will enable support for long paths, allowing the repository to handle paths longer than 260 characters.
194+
/// </summary>
195+
bool LongPaths { get; }
186196
}
187197

188198
/// <summary>
@@ -229,5 +239,8 @@ public CheckoutNotifyFlags CheckoutNotifyFlags
229239
{
230240
get { return internalOptions.CheckoutNotifyFlags; }
231241
}
242+
243+
/// <inheritdoc />
244+
public bool LongPaths { get; set; }
232245
}
233246
}

LibGit2Sharp/Core/GitCheckoutOptsWrapper.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ public GitCheckoutOptsWrapper(IConvertableToGitCheckoutOpts options, FilePath[]
2222
PathArray = GitStrArrayManaged.BuildFrom(paths);
2323
}
2424

25+
var checkout_strategy = options.CheckoutStrategy;
26+
27+
if (options.LongPaths)
28+
{
29+
checkout_strategy |= CheckoutStrategy.GIT_CHECKOUT_LONGPATHS;
30+
}
31+
2532
Options = new GitCheckoutOpts
2633
{
2734
version = 1,
28-
checkout_strategy = options.CheckoutStrategy,
35+
checkout_strategy = checkout_strategy,
2936
progress_cb = Callbacks.CheckoutProgressCallback,
3037
notify_cb = Callbacks.CheckoutNotifyCallback,
3138
notify_flags = options.CheckoutNotifyFlags,

LibGit2Sharp/MergeAndCheckoutOptionsBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public MergeAndCheckoutOptionsBase()
4646
/// </summary>
4747
public CheckoutProgressHandler OnCheckoutProgress { get; set; }
4848

49+
/// <inheritdoc />
50+
public bool LongPaths { get; set; }
51+
4952
/// <summary>
5053
/// Delegate that checkout will notify callers of
5154
/// certain conditions. The conditions that are reported is
@@ -69,6 +72,8 @@ CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
6972
}
7073
}
7174

75+
76+
7277
#endregion
7378
}
7479
}

LibGit2Sharp/RebaseOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@ CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
5454
GitCheckoutOptsWrapper.CheckoutStrategyFromFileConflictStrategy(FileConflictStrategy);
5555
}
5656
}
57+
58+
/// <inheritdoc />
59+
public bool LongPaths { get; set; }
5760
}
5861
}

LibGit2Sharp/SubmoduleUpdateOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,8 @@ CheckoutNotifyFlags IConvertableToGitCheckoutOpts.CheckoutNotifyFlags
4949
{
5050
get { return CheckoutNotifyFlags; }
5151
}
52+
53+
/// <inheritdoc />
54+
public bool LongPaths { get; set; }
5255
}
5356
}

0 commit comments

Comments
 (0)