8000 Add test for TreeChanges case-sensitivity · freevoid/libgit2sharp@dc208c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit dc208c9

Browse files
committed
Add test for TreeChanges case-sensitivity
1 parent 0394ec6 commit dc208c9

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePath()
395395

396396
using (Repository repo = Repository.Init(scd.DirectoryPath))
397397
{
398-
Blob mainContent = CreateBlob(repo, "awesome content\n");
399-
Blob linkContent = CreateBlob(repo, "../../objc/Nu.h");
398+
Blob mainContent = OdbHelper.CreateBlob(repo, "awesome content\n");
399+
Blob linkContent = OdbHelper.CreateBlob(repo, "../../objc/Nu.h");
400400

401401
string path = string.Format("include{0}Nu{0}Nu.h", Path.DirectorySeparatorChar);
402402

@@ -451,15 +451,6 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePath()
451451
}
452452
}
453453

454-
private static Blob CreateBlob(Repository repo, string content)
455-
{
456-
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(content)))
457-
using (var binReader = new BinaryReader(stream))
458-
{
459-
return repo.ObjectDatabase.CreateBlob(binReader);
460-
}
461-
}
462-
463454
[Fact]
464455
public void CanCompareATreeAgainstANullTree()
465456
{
@@ -558,5 +549,38 @@ private RepositoryOptions BuildFakeSystemConfigFilemodeOption(
558549

559550
return options;
560551
}
552+
553+
[Fact]
554+
public void RetrievingDiffChangesMustAlwaysBeCaseSensitive()
555+
{
556+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
557+
ObjectId treeOldOid, treeNewOid;
558+
559+
using (Repository repo = Repository.Init(scd.DirectoryPath))
560+
{
561+
Blob oldContent = OdbHelper.CreateBlob(repo, "awesome content\n");
562+
Blob newContent = OdbHelper.CreateBlob(repo, "more awesome content\n");
563+
564+
var td = new TreeDefinition()
565+
.Add("A.TXT", oldContent, Mode.NonExecutableFile)
566+
.Add("a.txt", oldContent, Mode.NonExecutableFile);
567+
568+
treeOldOid = repo.ObjectDatabase.CreateTree(td).Id;
569+
570+
td = new TreeDefinition()
571+
.Add("A.TXT", newContent, Mode.NonExecutableFile)
572+
.Add("a.txt", newContent, Mode.NonExecutableFile);
573+
574+
treeNewOid = repo.ObjectDatabase.CreateTree(td).Id;
575+
}
576+
577+
using (var repo = new Repository(scd.DirectoryPath))
578+
{
579+
var changes = repo.Diff.Compare(repo.Lookup<Tree>(treeOldOid), repo.Lookup<Tree>(treeNewOid));
580+
581+
Assert.Equal(ChangeKind.Modified, changes["a.txt"].Status);
582+
Assert.Equal(ChangeKind.Modified, changes["A.TXT"].Status);
583+
}
584+
}
561585
}
562586
}

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<Compile Include="ReferenceFixture.cs" />
105105
<Compile Include="RepositoryFixture.cs" />
106106
<Compile Include="TagFixture.cs" />
107+
<Compile Include="TestHelpers\OdbHelper.cs" />
107108
<Compile Include="TestHelpers\DirectoryHelper.cs" />
108109
<Compile Include="TestHelpers\ExpectedFetchState.cs" />
109110
<Compile Include="TestHelpers\TestRemoteInfo.cs" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.IO;
2+
using System.Text;
3+
4+
namespace LibGit2Sharp.Tests.TestHelpers
5+
{
6+
public static class OdbHelper
7+
{
8+
public static Blob CreateBlob(Repository repo, string content)
9+
{
10+
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(content)))
11+
using (var binReader = new BinaryReader(stream))
12+
{
13+
return repo.ObjectDatabase.CreateBlob(binReader);
14+
}
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)
0