8000 Add some .gitattributes handling test coverage · mm201/libgit2sharp@326ed86 · GitHub
[go: up one dir, main page]

Skip to content

Commit 326ed86

Browse files
committed
Add some .gitattributes handling test coverage
1 parent 83619e9 commit 326ed86

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.IO;
2+
using System.Text;
3+
using LibGit2Sharp.Tests.TestHelpers;
4+
using Xunit;
5+
6+
namespace LibGit2Sharp.Tests
7+
{
8+
public class AttributesFixture : BaseFixture
9+
{
10+
[Fact]
11+
public void StagingHonorsTheAttributesFiles()
12+
{
13+
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
14+
using (var repo = new Repository(path.RepositoryPath))
15+
{
16+
CreateAttributesFile(repo);
17+
18+
AssertNormalization(repo, "text.txt", true, "22c74203bace3c2e950278c7ab08da0fca9f4e9b");
19+
AssertNormalization(repo, "huh.dunno", true, "22c74203bace3c2e950278c7ab08da0fca9f4e9b");
20+
AssertNormalization(repo, "binary.data", false, "66eeff1fcbacf589e6d70aa70edd3fce5be2b37c");
21+
}
22+
}
23+
24+
private void AssertNormalization(Repository repo, string filename, bool shouldHaveBeenNormalized, string expectedSha)
25+
{
26+
var sb = new StringBuilder();
27+
sb.Append("I'm going to be dynamically processed\r\n");
28+
sb.Append("And my line endings...\r\n");
29+
sb.Append("...are going to be\n");
30+
sb.Append("normalized!\r\n");
31+
32+
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, filename), sb.ToString());
33+
34+
repo.Index.Stage(filename);
35+
36+
IndexEntry entry = repo.Index[filename];
37+
Assert.NotNull(entry);
38+
39+
Assert.Equal(expectedSha, entry.Id.Sha);
40+
41+
var blob = repo.Lookup<Blob>(entry.Id);
42+
Assert.NotNull(blob);
43+
44+
Assert.Equal(!shouldHaveBeenNormalized, blob.ContentAsUtf8().Contains("\r"));
45+
}
46+
47+
private void CreateAttributesFile(Repository repo)
48+
{
49+
const string relativePath =< 8000 /span> ".gitattributes";
50+
string fullFilePath = Path.Combine(repo.Info.WorkingDirectory, relativePath);
51+
52+
var sb = new StringBuilder();
53+
sb.Append("* text=auto\n");
54+
sb.Append("*.txt text\n");
55+
sb.Append("*.data binary\n");
56+
57+
File.WriteAllText(fullFilePath, sb.ToString());
58+
}
59+
}
60+
}

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
</ItemGroup>
4747
<ItemGroup>
4848
<Compile Include="ConfigurationFixture.cs" />
49+
<Compile Include="AttributesFixture.cs" />
4950
<Compile Include="ObjectDatabaseFixture.cs" />
5051
<Compile Include="DiffFixture.cs" />
5152
<Compile Include="ResetFixture.cs" />

0 commit comments

Comments
 (0)
0