Skip to content

Commit 6ef2168

Browse files
committed
Normalize submodule paths on lookup
Fixes libgit2/libgit2#1845
1 parent 936407f commit 6ef2168

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

LibGit2Sharp.Tests/SubmoduleFixture.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
34
using LibGit2Sharp.Tests.TestHelpers;
45
using Xunit;
@@ -103,14 +104,17 @@ public void CanEnumerateRepositorySubmodules()
103104
}
104105

105106
[Theory]
106-
[InlineData("sm_changed_head")]
107-
[InlineData("sm_changed_head/")]
108-
public void CanStageChangeInSubmoduleViaIndexStage(string submodulePath)
107+
[InlineData("sm_changed_head", false)]
108+
[InlineData("sm_changed_head", true)]
109+
public void CanStageChangeInSubmoduleViaIndexStage(string submodulePath, bool appendPathSeparator)
109110
{
111+
submodulePath += appendPathSeparator ? Path.DirectorySeparatorChar : default(char?);
112+
110113
var path = CloneSubmoduleTestRepo();
111114
using (var repo = new Repository(path))
112115
{
113116
var submodule = repo.Submodules[submodulePath];
117+
Assert.NotNull(submodule);
114118

115119
var statusBefore = submodule.RetrieveStatus();
116120
Assert.Equal(SubmoduleStatus.WorkDirModified, statusBefore & SubmoduleStatus.WorkDirModified);
@@ -123,21 +127,24 @@ public void CanStageChangeInSubmoduleViaIndexStage(string submodulePath)
123127
}
124128

125129
[Theory]
126-
[InlineData("sm_changed_head")]
127-
[InlineData("sm_changed_head/")]
128-
public void CanStageChangeInSubmoduleViaIndexStageWithOtherPaths(string submodulePath)
130+
[InlineData("sm_changed_head", false)]
131+
[InlineData("sm_changed_head", true)]
132+
public void CanStageChangeInSubmoduleViaIndexStageWithOtherPaths(string submodulePath, bool appendPathSeparator)
129133
{
134+
submodulePath += appendPathSeparator ? Path.DirectorySeparatorChar : default(char?);
135+
130136
var path = CloneSubmoduleTestRepo();
131137
using (var repo = new Repository(path))
132138
{
133139
var submodule = repo.Submodules[submodulePath];
140+
Assert.NotNull(submodule);
134141

135142
var statusBefore = submodule.RetrieveStatus();
136143
Assert.Equal(SubmoduleStatus.WorkDirModified, statusBefore & SubmoduleStatus.WorkDirModified);
137144

138145
Touch(repo.Info.WorkingDirectory, "new-file.txt");
139146

140-
repo.Index.Stage(new[]{ "new-file.txt", submodulePath, "does-not-exist.txt" });
147+
repo.Index.Stage(new[] { "new-file.txt", submodulePath, "does-not-exist.txt" });
141148

142149
var statusAfter = submodule.RetrieveStatus();
143150
Assert.Equal(SubmoduleStatus.IndexModified, statusAfter & SubmoduleStatus.IndexModified);

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ internal delegate int git_status_cb(
10471047
internal static extern int git_submodule_lookup(
10481048
out SubmoduleSafeHandle reference,
10491049
RepositorySafeHandle repo,
1050-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(Utf8Marshaler))] string name);
1050+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath name);
10511051

10521052
internal delegate int submodule_callback(
10531053
IntPtr sm,

LibGit2Sharp/Core/Proxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,7 @@ public static ICollection<TResult> git_status_foreach<TResult>(RepositorySafeHan
19781978
/// Returns a handle to the corresponding submodule,
19791979
/// or an invalid handle if a submodule is not found.
19801980
/// </summary>
1981-
public static SubmoduleSafeHandle git_submodule_lookup(RepositorySafeHandle repo, string name)
1981+
public static SubmoduleSafeHandle git_submodule_lookup(RepositorySafeHandle repo, FilePath name)
19821982
{
19831983
using (ThreadAffinity())
19841984
{

0 commit comments

Comments
 (0)