Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-04-30 21:35:48 +0400
committernulltoken <emeric.fermas@gmail.com>2012-05-15 21:30:41 +0400
commit326ed862b9b5d932749cbc17611c6ca28cbe6591 (patch)
treedefdcb964b9e49f96c6e17ffe97cc53ab8553a13
parent83619e93627793505342d5da35a4785ff6ecfcfb (diff)
Add some .gitattributes handling test coverage
-rw-r--r--LibGit2Sharp.Tests/AttributesFixture.cs60
-rw-r--r--LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj1
2 files changed, 61 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/AttributesFixture.cs b/LibGit2Sharp.Tests/AttributesFixture.cs
new file mode 100644
index 00000000..438e2b62
--- /dev/null
+++ b/LibGit2Sharp.Tests/AttributesFixture.cs
@@ -0,0 +1,60 @@
+using System.IO;
+using System.Text;
+using LibGit2Sharp.Tests.TestHelpers;
+using Xunit;
+
+namespace LibGit2Sharp.Tests
+{
+ public class AttributesFixture : BaseFixture
+ {
+ [Fact]
+ public void StagingHonorsTheAttributesFiles()
+ {
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
+ using (var repo = new Repository(path.RepositoryPath))
+ {
+ CreateAttributesFile(repo);
+
+ AssertNormalization(repo, "text.txt", true, "22c74203bace3c2e950278c7ab08da0fca9f4e9b");
+ AssertNormalization(repo, "huh.dunno", true, "22c74203bace3c2e950278c7ab08da0fca9f4e9b");
+ AssertNormalization(repo, "binary.data", false, "66eeff1fcbacf589e6d70aa70edd3fce5be2b37c");
+ }
+ }
+
+ private void AssertNormalization(Repository 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");
+
+ File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, filename), sb.ToString());
+
+ repo.Index.Stage(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.ContentAsUtf8().Contains("\r"));
+ }
+
+ private void CreateAttributesFile(Repository repo)
+ {
+ const string relativePath = ".gitattributes";
+ string fullFilePath = Path.Combine(repo.Info.WorkingDirectory, relativePath);
+
+ var sb = new StringBuilder();
+ sb.Append("* text=auto\n");
+ sb.Append("*.txt text\n");
+ sb.Append("*.data binary\n");
+
+ File.WriteAllText(fullFilePath, sb.ToString());
+ }
+ }
+}
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index ae793e6a..08d35190 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -46,6 +46,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigurationFixture.cs" />
+ <Compile Include="AttributesFixture.cs" />
<Compile Include="ObjectDatabaseFixture.cs" />
<Compile Include="DiffFixture.cs" />
<Compile Include="ResetFixture.cs" />