Skip to content

Fixes RebaseFixture tests by adding .gitattributes file to repo #1137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions LibGit2Sharp.Tests/FilterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ private unsafe bool CharArrayAreEqual(char[] array1, char[] array2, int count)
return true;
}


private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, string content)
{
FileInfo expectedPath;
Expand Down Expand Up @@ -350,11 +349,6 @@ private Repository CreateTestRepository(string path)
return repository;
}

private static void CreateAttributesFile(IRepository repo, string attributeEntry)
{
Touch(repo.Info.WorkingDirectory, ".gitattributes", attributeEntry);
}

class EmptyFilter : Filter
{
public EmptyFilter(string name, IEnumerable<FilterAttributeEntry> attributes)
Expand Down
5 changes: 0 additions & 5 deletions LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,5 @@ private static Blob CommitOnBranchAndReturnDatabaseBlob(Repository repo, string
var blob = (Blob)commit.Tree[fileName].Target;
return blob;
}

private static void CreateAttributesFile(IRepository repo, string attributeEntry)
{
Touch(repo.Info.WorkingDirectory, ".gitattributes", attributeEntry);
}
}
}
61 changes: 39 additions & 22 deletions LibGit2Sharp.Tests/RebaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,21 @@ int IEqualityComparer<CompletedRebaseStepInfo>.GetHashCode(CompletedRebaseStepIn
/// <summary>
/// Verify a single rebase, but in more detail.
/// </summary>
[Fact]
public void VerifyRebaseDetailed()
[Theory]
[InlineData("* text=auto", "\r\n", new[] { "2cad6e96a0028f1764dcbde6292a9a1471acb114", "18fd3deebe6124b5dacc8426d589d617a968e8d1", "048977d8cb90d530e83cc615a17a49f3068f68c1" })]
[InlineData("* text=auto", "\n", new[] { "2cad6e96a0028f1764dcbde6292a9a1471acb114", "18fd3deebe6124b5dacc8426d589d617a968e8d1", "048977d8cb90d530e83cc615a17a49f3068f68c1" })]
[InlineData("* text=auto\n*.txt eol=lf", "\n", new[] { "577d176b00a55e88e9b34da87e4357dfc9a486fd", "ea0ad4d8b500394a61874ebfda5904376e2b1098", "521b8383ca3fde9e369587492e7a3945677f1b2c" })]
[InlineData("* text=auto\r\n*.txt eol=crlf", "\r\n", new[] { "67d29fdf654ac4773c9405ab4b54aa7ff092f339", "7b70c02e175d378b44ea28aeeece775cd972047a", "81f203dbfe00a5c1ecd9c0e6b03705e6cffda5c0" })]
[InlineData("* binary", "\r\n", new[] { "f5a5ded935597108709224170accddc5aeb5c287", "518adb8bb1ea1058d1825d3fe08d27f80c0e829b", "d2db503ab553c970d34e1b5e3ff68768adef05bc" })]
[InlineData("* binary", "\n", new[] { "93a0e9680246d1f1e43fbd5308f7936424d9e81a", "5fd40bffbdd884632c330a254a2bd1dfaaaad3c1", "4df5c91b2d8318781b07d04f6bfa77304c372f1e" })]
public void VerifyRebaseDetailed(string attributes, string lineEnding, string[] expectedIds)
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
var path = Repository.Init(scd.DirectoryPath);

using (Repository repo = new Repository(path))
{
ConstructRebaseTestRepository(repo);
ConstructRebaseTestRepository(repo, attributes, lineEnding);

Branch initialBranch = repo.Branches[topicBranch1Name];
Branch upstreamBranch = repo.Branches[masterBranch2Name];
Expand Down Expand Up @@ -262,9 +268,9 @@ public void VerifyRebaseDetailed()

List<ObjectId> expectedTreeIds = new List<ObjectId>()
{
new ObjectId("447bad85bcc1882037848370620a6f88e8ee264e"),
new ObjectId("3b0fc846952496a64b6149064cde21215daca8f8"),
new ObjectId("a2d114246012daf3ef8e7ccbfbe91889a24e1e60"),
new ObjectId(expectedIds[0]),
new ObjectId(expectedIds[1]),
new ObjectId(expectedIds[2]),
};

List<Commit> rebasedCommits = repo.Commits.QueryBy(commitFilter).ToList();
Expand Down Expand Up @@ -591,18 +597,24 @@ public void CurrentStepInfoIsNullWhenNotRebasing()
}
}

[Fact]
public void CanRebaseHandlePatchAlreadyApplied()
[Theory]
[InlineData("* text=auto", "\r\n", "379e80ed7824be7672e1e30ddd8f44aa081d57d4")]
[InlineData("* text=auto", "\n", "379e80ed7824be7672e1e30ddd8f44aa081d57d4")]
[InlineData("* text=auto\n*.txt eol=lf", "\n", "94121eeebf7cfe0acf22425eab36fcdc737132b6")]
[InlineData("* text=auto\r\n*.txt eol=crlf", "\r\n", "dad06142cc632aea81cbc8486583011c4d622580")]
[InlineData("* binary", "\r\n", "44492d98b725189cfc0203d4192dfbb1fd34bf02")]
[InlineData("* binary", "\n", "f4b5b95de77f4cd97b4728617bae2dd8ba9af914")]
public void CanRebaseHandlePatchAlreadyApplied(string attributes, string lineEnding, string expectedShaText)
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
var path = Repository.Init(scd.DirectoryPath);
using (Repository repo = new Repository(path))
{
ConstructRebaseTestRepository(repo);
ConstructRebaseTestRepository(repo, attributes, lineEnding);

repo.Checkout(topicBranch1Name);

Branch topicBranch1Prime = repo.CreateBranch(topicBranch1PrimeName, masterBranch1Name);
Branch topicBranch1Prime = repo.CreateBranch(topicBranch1PrimeName, masterBranch1Name);

string newFileRelativePath = "new_file.txt";
Touch(repo.Info.WorkingDirectory, newFileRelativePath, "New Content");
Expand Down Expand Up @@ -631,7 +643,7 @@ public void CanRebaseHandlePatchAlreadyApplied()
};

repo.Rebase.Start(null, upstreamBranch, null, Constants.Identity2, options);
ObjectId secondCommitExpectedTreeId = new ObjectId("ac04bf04980c9be72f64ba77fd0d9088a40ed681");
ObjectId secondCommitExpectedTreeId = new ObjectId(expectedShaText);
Signature secondCommitAuthorSignature = Constants.Signature;
Identity secondCommitCommiterIdentity = Constants.Identity2;

Expand All @@ -642,7 +654,7 @@ public void CanRebaseHandlePatchAlreadyApplied()
Assert.NotNull(rebaseResults[1].Commit);

// This is the expected tree ID of the new commit.
Assert.True(ObjectId.Equals(secondCommitExpectedTreeId, rebaseResults[1].Commit.Tree.Id));
Assert.Equal(secondCommitExpectedTreeId, rebaseResults[1].Commit.Tree.Id);
Assert.True(Signature.Equals(secondCommitAuthorSignature, rebaseResults[1].Commit.Author));
Assert.Equal<string>(secondCommitCommiterIdentity.Name, rebaseResults[1].Commit.Committer.Name, StringComparer.Ordinal);
Assert.Equal<string>(secondCommitCommiterIdentity.Email, rebaseResults[1].Commit.Committer.Email, StringComparer.Ordinal);
Expand All @@ -664,7 +676,7 @@ public void RebasingInBareRepositoryThrows()
}
}

private void ConstructRebaseTestRepository(Repository repo)
private void ConstructRebaseTestRepository(Repository repo, string attributes = "* text=auto", string lineEnding = "\r\n")
{
// Constructs a graph that looks like:
// * -- * -- * (modifications to c.txt)
Expand Down Expand Up @@ -700,6 +712,11 @@ private void ConstructRebaseTestRepository(Repository repo)
string workdir = repo.Info.WorkingDirectory;
Commit commit = null;

CreateAttributesFile(repo, attributes);

repo.Stage(".gitattributes");
commit = repo.Commit("setup", Constants.Signature, Constants.Signature, new CommitOptions());

Touch(workdir, filePathA, fileContentA1);
repo.Stage(filePathA);
commit = repo.Commit("commit 1", Constants.Signature, Constants.Signature, new CommitOptions());
Expand All @@ -714,29 +731,29 @@ private void ConstructRebaseTestRepository(Repository repo)

Branch masterBranch1 = repo.CreateBranch(masterBranch1Name, commit);

Touch(workdir, filePathB, string.Join(Environment.NewLine, fileContentB1, fileContentB2));
Touch(workdir, filePathB, string.Join(lineEnding, fileContentB1, fileContentB2));
repo.Stage(filePathB);
commit = repo.Commit("commit 4", Constants.Signature, Constants.Signature, new CommitOptions());

Touch(workdir, filePathB, string.Join(Environment.NewLine, fileContentB1, fileContentB2, fileContentB3));
Touch(workdir, filePathB, string.Join(lineEnding, fileContentB1, fileContentB2, fileContentB3));
repo.Stage(filePathB);
commit = repo.Commit("commit 5", Constants.Signature, Constants.Signature, new CommitOptions());

Touch(workdir, filePathB, string.Join(Environment.NewLine, fileContentB1, fileContentB2, fileContentB3, fileContentB4));
Touch(workdir, filePathB, string.Join(lineEnding, fileContentB1, fileContentB2, fileContentB3, fileContentB4));
repo.Stage(filePathB);
commit = repo.Commit("commit 6", Constants.Signature, Constants.Signature, new CommitOptions());

repo.CreateBranch(topicBranch1Name, commit);

Touch(workdir, filePathC, string.Join(Environment.NewLine, fileContentC1, fileContentC2));
Touch(workdir, filePathC, string.Join(lineEnding, fileContentC1, fileContentC2));
repo.Stage(filePathC);
commit = repo.Commit("commit 7", Constants.Signature, Constants.Signature, new CommitOptions());

Touch(workdir, filePathC, string.Join(Environment.NewLine, fileContentC1, fileContentC2, fileContentC3));
Touch(workdir, filePathC, string.Join(lineEnding, fileContentC1, fileContentC2, fileContentC3));
repo.Stage(filePathC);
commit = repo.Commit("commit 8", Constants.Signature, Constants.Signature, new CommitOptions());

Touch(workdir, filePathC, string.Join(Environment.NewLine, fileContentC1, fileContentC2, fileContentC3, fileContentC4));
Touch(workdir, filePathC, string.Join(lineEnding, fileContentC1, fileContentC2, fileContentC3, fileContentC4));
repo.Stage(filePathC);
commit = repo.Commit("commit 9", Constants.Signature, Constants.Signature, new CommitOptions());

Expand All @@ -747,18 +764,18 @@ private void ConstructRebaseTestRepository(Repository repo)
repo.Stage(filePathD);
commit = repo.Commit("commit 10", Constants.Signature, Constants.Signature, new CommitOptions());

Touch(workdir, filePathD, string.Join(Environment.NewLine, fileContentD1, fileContentD2));
Touch(workdir, filePathD, string.Join(lineEnding, fileContentD1, fileContentD2));
repo.Stage(filePathD);
commit = repo.Commit("commit 11", Constants.Signature, Constants.Signature, new CommitOptions());

Touch(workdir, filePathD, string.Join(Environment.NewLine, fileContentD1, fileContentD2, fileContentD3));
Touch(workdir, filePathD, string.Join(lineEnding, fileContentD1, fileContentD2, fileContentD3));
repo.Stage(filePathD);
commit = repo.Commit("commit 12", Constants.Signature, Constants.Signature, new CommitOptions());

repo.CreateBranch(masterBranch2Name, commit);

// Create commit / branch that conflicts with T1 and T2
Touch(workdir, filePathB, string.Join(Environment.NewLine, fileContentB1, fileContentB2 + fileContentB3 + fileContentB4));
Touch(workdir, filePathB, string.Join(lineEnding, fileContentB1, fileContentB2 + fileContentB3 + fileContentB4));
repo.Stage(filePathB);
commit = repo.Commit("commit 13", Constants.Signature, Constants.Signature, new CommitOptions());
repo.CreateBranch(conflictBranch1Name, commit);
Expand Down
9 changes: 7 additions & 2 deletions LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static BaseFixture()
protected static DateTimeOffset TruncateSubSeconds(DateTimeOffset dto)
{
int seconds = dto.ToSecondsSinceEpoch();
return Epoch.ToDateTimeOffset(seconds, (int) dto.Offset.TotalMinutes);
return Epoch.ToDateTimeOffset(seconds, (int)dto.Offset.TotalMinutes);
}

private static void SetUpTestEnvironment()
Expand Down Expand Up @@ -258,7 +258,7 @@ protected void RequiresDotNetOrMonoGreaterThanOrEqualTo(System.Version minimumVe
throw new InvalidOperationException("Cannot access Mono.RunTime.GetDisplayName() method.");
}

var version = (string) displayName.Invoke(null, null);
var version = (string)displayName.Invoke(null, null);

System.Version current;

Expand Down Expand Up @@ -460,5 +460,10 @@ public void AssertBelongsToARepository<T>(IRepository repo, T instance)
{
Assert.Same(repo, ((IBelongToARepository)instance).Repository);
}

protected void CreateAttributesFile(IRepository repo, string attributeEntry)
{
Touch(repo.Info.WorkingDirectory, ".gitattributes", attributeEntry);
}
}
}