/
AttributesFixture.cs
55 lines (44 loc) · 1.85 KB
/
AttributesFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Text;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
namespace LibGit2Sharp.Tests
{
public class AttributesFixture : BaseFixture
{
[Fact]
public void StagingHonorsTheAttributesFiles()
{
using (var repo = new Repository(InitNewRepository()))
{
CreateAttributesFile(repo);
AssertNormalization(repo, "text.txt", true, "22c74203bace3c2e950278c7ab08da0fca9f4e9b");
AssertNormalization(repo, "huh.dunno", true, "22c74203bace3c2e950278c7ab08da0fca9f4e9b");
AssertNormalization(repo, "binary.data", false, "66eeff1fcbacf589e6d70aa70edd3fce5be2b37c");
}
}
private static void AssertNormalization(IRepository repo, string filename, bool shouldHaveBeenNormalized, string expectedSha)
{
var sb = new StringBuilder();
sb.Append("I'm going to be dynamically processed\r\n");
sb.Append("And my line endings...\r\n");
sb.Append("...are going to be\n");
sb.Append("normalized!\r\n");
Touch(repo.Info.WorkingDirectory, filename, sb.ToString());
Commands.Stage(repo, filename);
IndexEntry entry = repo.Index[filename];
Assert.NotNull(entry);
Assert.Equal(expectedSha, entry.Id.Sha);
var blob = repo.Lookup<Blob>(entry.Id);
Assert.NotNull(blob);
Assert.Equal(!shouldHaveBeenNormalized, blob.GetContentText().Contains("\r"));
}
private static void CreateAttributesFile(IRepository repo)
{
var sb = new StringBuilder();
sb.Append("* text=auto\n");
sb.Append("*.txt text\n");
sb.Append("*.data binary\n");
Touch(repo.Info.WorkingDirectory, ".gitattributes", sb.ToString());
}
}
}