Skip to content

Commit

Permalink
Add support for long file paths in CheckoutOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Kudelin authored and bording committed Nov 24, 2024
1 parent 17a2dee commit 4a693c9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 1 deletion.
25 changes: 25 additions & 0 deletions LibGit2Sharp.Tests/CloneFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,5 +629,30 @@ public void CanCloneWithCustomHeaders()
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, cloneOptions);
Assert.True(Directory.Exists(clonedRepoPath));
}

[Fact]
public void CanCloneWithLongPaths()
{
var scd = BuildSelfCleaningDirectory();

var cloneOptions = new CloneOptions
{
LongPaths = true
};

string clonedRepoPath = Repository.Clone("https://github.com/luiswolff/test-long-file-path.git", scd.DirectoryPath, cloneOptions);

using (var repo = new Repository(clonedRepoPath))
{
string dir = repo.Info.Path;
Assert.True(Path.IsPathRooted(dir));
Assert.True(Directory.Exists(dir));
Assert.NotNull(repo.Info.WorkingDirectory);
Assert.Equal(Path.Combine(scd.RootedDirectoryPath, ".git" + Path.DirectorySeparatorChar), repo.Info.Path);
Assert.False(repo.Info.IsBare);

// Add additional assertions if necessary to verify long path support
}
}
}
}
3 changes: 3 additions & 0 deletions LibGit2Sharp/CheckoutOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public sealed class CheckoutOptions : IConvertableToGitCheckoutOpts
/// controlled with the CheckoutNotifyFlags property.
public CheckoutProgressHandler OnCheckoutProgress { get; set; }

/// <inheritdoc />
public bool LongPaths { get; set; }

CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
{
get
Expand Down
3 changes: 3 additions & 0 deletions LibGit2Sharp/CloneOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public CloneOptions()
/// </summary>
public bool IsBare { get; set; }

/// <inheritdoc />
public bool LongPaths { get; set; }

/// <summary>
/// If true, the origin's HEAD will be checked out. This only applies
/// to non-bare repositories.
Expand Down
13 changes: 13 additions & 0 deletions LibGit2Sharp/Core/GitCheckoutOpts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ internal enum CheckoutStrategy
/// </summary>
GIT_CHECKOUT_DONT_WRITE_INDEX = (1 << 23),

/// <summary>
/// Support for long file paths.
/// </summary>
GIT_CHECKOUT_LONGPATHS = (1 << 24),

// THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED

/// <summary>
Expand Down Expand Up @@ -183,6 +188,11 @@ internal interface IConvertableToGitCheckoutOpts
CheckoutStrategy CheckoutStrategy { get; }

CheckoutNotifyFlags CheckoutNotifyFlags { get; }

/// <summary>
/// True will enable support for long paths, allowing the repository to handle paths longer than 260 characters.
/// </summary>
bool LongPaths { get; }
}

/// <summary>
Expand Down Expand Up @@ -229,5 +239,8 @@ public CheckoutNotifyFlags CheckoutNotifyFlags
{
get { return internalOptions.CheckoutNotifyFlags; }
}

/// <inheritdoc />
public bool LongPaths { get; set; }
}
}
9 changes: 8 additions & 1 deletion LibGit2Sharp/Core/GitCheckoutOptsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ public GitCheckoutOptsWrapper(IConvertableToGitCheckoutOpts options, FilePath[]
PathArray = GitStrArrayManaged.BuildFrom(paths);
}

var checkout_strategy = options.CheckoutStrategy;

if (options.LongPaths)
{
checkout_strategy |= CheckoutStrategy.GIT_CHECKOUT_LONGPATHS;
}

Options = new GitCheckoutOpts
{
version = 1,
checkout_strategy = options.CheckoutStrategy,
checkout_strategy = checkout_strategy,
progress_cb = Callbacks.CheckoutProgressCallback,
notify_cb = Callbacks.CheckoutNotifyCallback,
notify_flags = options.CheckoutNotifyFlags,
Expand Down
5 changes: 5 additions & 0 deletions LibGit2Sharp/MergeAndCheckoutOptionsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public MergeAndCheckoutOptionsBase()
/// </summary>
public CheckoutProgressHandler OnCheckoutProgress { get; set; }

/// <inheritdoc />
public bool LongPaths { get; set; }

/// <summary>
/// Delegate that checkout will notify callers of
/// certain conditions. The conditions that are reported is
Expand All @@ -69,6 +72,8 @@ CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
}
}



#endregion
}
}
3 changes: 3 additions & 0 deletions LibGit2Sharp/RebaseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
GitCheckoutOptsWrapper.CheckoutStrategyFromFileConflictStrategy(FileConflictStrategy);
}
}

/// <inheritdoc />
public bool LongPaths { get; set; }
}
}
3 changes: 3 additions & 0 deletions LibGit2Sharp/SubmoduleUpdateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ CheckoutNotifyFlags IConvertableToGitCheckoutOpts.CheckoutNotifyFlags
{
get { return CheckoutNotifyFlags; }
}

/// <inheritdoc />
public bool LongPaths { get; set; }
}
}

0 comments on commit 4a693c9

Please sign in to comment.