Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

61 lines (48 sloc) 2.168 kb
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 static 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 static 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());
}
}
}
Jump to Line
Something went wrong with that request. Please try again.