8000 Teach repo.Ignore.IsPathIgnored() to cope with Windows directory sepa… · mm201/libgit2sharp@5c99eee · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c99eee

Browse files
committed
Teach repo.Ignore.IsPathIgnored() to cope with Windows directory separators
Fix libgit2#347
1 parent 090b2de commit 5c99eee

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

LibGit2Sharp.Tests/IgnoreFixture.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using LibGit2Sharp.Tests.TestHelpers;
55
using Xunit;
6+
using Xunit.Extensions;
67

78
namespace LibGit2Sharp.Tests
89
{
@@ -66,5 +67,22 @@ public void AddingATemporaryRuleWithBadParamsThrows()
6667
Assert.Throws<ArgumentNullException>(() => repo.Ignore.AddTemporaryRules(null));
6768
}
6869
}
70+
71+
[Fact]
72+
public void CanCheckIfAPathIsIgnoredUsingThePreferedPlatformDirectorySeparatorChar()
73+
{
74+
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
75+
76+
using (var repo = new Repository(path.RepositoryPath))
77+
{
78+
string ignorePath = Path.Combine(repo.Info.WorkingDirectory, ".gitignore");
79+
File.WriteAllText(ignorePath, "/NewFolder\n/NewFolder/NewFolder");
80+
81+
Assert.False(repo.Ignore.IsPathIgnored("File.txt"));
82+
Assert.True(repo.Ignore.IsPathIgnored("NewFolder"));
83+
Assert.True(repo.Ignore.IsPathIgnored(string.Format(@"NewFolder{0}NewFolder", Path.DirectorySeparatorChar)));
84+
Assert.True(repo.Ignore.IsPathIgnored(string.Format(@"NewFolder{0}NewFolder{0}File.txt", Path.DirectorySeparatorChar)));
85+
}
86+
}
6987
}
7088
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ internal static extern int git_ignore_add_rule(
403403
internal static extern int git_ignore_path_is_ignored(
404404
out int ignored,
405405
RepositorySafeHandle repo,
406-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Utf8Marshaler))] string path);
406+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path);
407407

408408
[DllImport(libgit2)]
409409
internal static extern int git_index_add_bypath(

0 commit comments

Comments
 (0)
0