Skip to content

Commit 84f9f65

Browse files
author
J Wyman
committed
Fixes RebaseFixture tests by adding .gitattributes file to repo.
Changed two `RebaseFixture` tests from `Fact` to `Theory` to support testing multiple .gitattribute values. Everthing works on Windows with `autocrlf` true or false.
1 parent 2587d57 commit 84f9f65

File tree

4 files changed

+46
-35
lines changed

4 files changed

+46
-35
lines changed

‎LibGit2Sharp.Tests/FilterFixture.cs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ private unsafe bool CharArrayAreEqual(char[] array1, char[] array2, int count)
304304
returntrue;
305305
}
306306

307-
308307
privateFileInfoCheckoutFileForSmudge(stringrepoPath,stringbranchName,stringcontent)
309308
{
310309
FileInfoexpectedPath;
@@ -350,11 +349,6 @@ private Repository CreateTestRepository(string path)
350349
returnrepository;
351350
}
352351

353-
privatestaticvoidCreateAttributesFile(IRepositoryrepo,stringattributeEntry)
354-
{
355-
Touch(repo.Info.WorkingDirectory,".gitattributes",attributeEntry);
356-
}
357-
358352
classEmptyFilter:Filter
359353
{
360354
publicEmptyFilter(stringname,IEnumerable<FilterAttributeEntry>attributes)

‎LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,5 @@ private static Blob CommitOnBranchAndReturnDatabaseBlob(Repository repo, string
216216
varblob=(Blob)commit.Tree[fileName].Target;
217217
returnblob;
218218
}
219-
220-
privatestaticvoidCreateAttributesFile(IRepositoryrepo,stringattributeEntry)
221-
{
222-
Touch(repo.Info.WorkingDirectory,".gitattributes",attributeEntry);
223-
}
224219
}
225220
}

‎LibGit2Sharp.Tests/RebaseFixture.cs‎

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,21 @@ int IEqualityComparer<CompletedRebaseStepInfo>.GetHashCode(CompletedRebaseStepIn
190190
/// <summary>
191191
/// Verify a single rebase, but in more detail.
192192
/// </summary>
193-
[Fact]
194-
publicvoidVerifyRebaseDetailed()
193+
[Theory]
194+
[InlineData("* text=auto","\r\n",new[]{"2cad6e96a0028f1764dcbde6292a9a1471acb114","18fd3deebe6124b5dacc8426d589d617a968e8d1","048977d8cb90d530e83cc615a17a49f3068f68c1"})]
195+
[InlineData("* text=auto","\n",new[]{"2cad6e96a0028f1764dcbde6292a9a1471acb114","18fd3deebe6124b5dacc8426d589d617a968e8d1","048977d8cb90d530e83cc615a17a49f3068f68c1"})]
196+
[InlineData("* text=auto\n*.txt eol=lf","\n",new[]{"577d176b00a55e88e9b34da87e4357dfc9a486fd","ea0ad4d8b500394a61874ebfda5904376e2b1098","521b8383ca3fde9e369587492e7a3945677f1b2c"})]
197+
[InlineData("* text=auto\r\n*.txt eol=crlf","\r\n",new[]{"67d29fdf654ac4773c9405ab4b54aa7ff092f339","7b70c02e175d378b44ea28aeeece775cd972047a","81f203dbfe00a5c1ecd9c0e6b03705e6cffda5c0"})]
198+
[InlineData("* binary","\r\n",new[]{"f5a5ded935597108709224170accddc5aeb5c287","518adb8bb1ea1058d1825d3fe08d27f80c0e829b","d2db503ab553c970d34e1b5e3ff68768adef05bc"})]
199+
[InlineData("* binary","\n",new[]{"93a0e9680246d1f1e43fbd5308f7936424d9e81a","5fd40bffbdd884632c330a254a2bd1dfaaaad3c1","4df5c91b2d8318781b07d04f6bfa77304c372f1e"})]
200+
publicvoidVerifyRebaseDetailed(stringattributes,stringlineEnding,string[]expectedIds)
195201
{
196202
SelfCleaningDirectoryscd=BuildSelfCleaningDirectory();
197203
varpath=Repository.Init(scd.DirectoryPath);
198204

199205
using(Repositoryrepo=newRepository(path))
200206
{
201-
ConstructRebaseTestRepository(repo);
207+
ConstructRebaseTestRepository(repo,attributes,lineEnding);
202208

203209
BranchinitialBranch=repo.Branches[topicBranch1Name];
204210
BranchupstreamBranch=repo.Branches[masterBranch2Name];
@@ -262,9 +268,9 @@ public void VerifyRebaseDetailed()
262268

263269
List<ObjectId>expectedTreeIds=newList<ObjectId>()
264270
{
265-
newObjectId("447bad85bcc1882037848370620a6f88e8ee264e"),
266-
newObjectId("3b0fc846952496a64b6149064cde21215daca8f8"),
267-
newObjectId("a2d114246012daf3ef8e7ccbfbe91889a24e1e60"),
271+
newObjectId(expectedIds[0]),
272+
newObjectId(expectedIds[1]),
273+
newObjectId(expectedIds[2]),
268274
};
269275

270276
List<Commit>rebasedCommits=repo.Commits.QueryBy(commitFilter).ToList();
@@ -591,18 +597,24 @@ public void CurrentStepInfoIsNullWhenNotRebasing()
591597
}
592598
}
593599

594-
[Fact]
595-
publicvoidCanRebaseHandlePatchAlreadyApplied()
600+
[Theory]
601+
[InlineData("* text=auto","\r\n","379e80ed7824be7672e1e30ddd8f44aa081d57d4")]
602+
[InlineData("* text=auto","\n","379e80ed7824be7672e1e30ddd8f44aa081d57d4")]
603+
[InlineData("* text=auto\n*.txt eol=lf","\n","94121eeebf7cfe0acf22425eab36fcdc737132b6")]
604+
[InlineData("* text=auto\r\n*.txt eol=crlf","\r\n","dad06142cc632aea81cbc8486583011c4d622580")]
605+
[InlineData("* binary","\r\n","44492d98b725189cfc0203d4192dfbb1fd34bf02")]
606+
[InlineData("* binary","\n","f4b5b95de77f4cd97b4728617bae2dd8ba9af914")]
607+
publicvoidCanRebaseHandlePatchAlreadyApplied(stringattributes,stringlineEnding,stringexpectedShaText)
596608
{
597609
SelfCleaningDirectoryscd=BuildSelfCleaningDirectory();
598610
varpath=Repository.Init(scd.DirectoryPath);
599611
using(Repositoryrepo=newRepository(path))
600612
{
601-
ConstructRebaseTestRepository(repo);
613+
ConstructRebaseTestRepository(repo,attributes,lineEnding);
602614

603615
repo.Checkout(topicBranch1Name);
604616

605-
BranchtopicBranch1Prime=repo.CreateBranch(topicBranch1PrimeName,masterBranch1Name);
617+
BranchtopicBranch1Prime=repo.CreateBranch(topicBranch1PrimeName,masterBranch1Name);
606618

607619
stringnewFileRelativePath="new_file.txt";
608620
Touch(repo.Info.WorkingDirectory,newFileRelativePath,"New Content");
@@ -631,7 +643,7 @@ public void CanRebaseHandlePatchAlreadyApplied()
631643
};
632644

633645
repo.Rebase.Start(null,upstreamBranch,null,Constants.Identity2,options);
634-
ObjectIdsecondCommitExpectedTreeId=newObjectId("ac04bf04980c9be72f64ba77fd0d9088a40ed681");
646+
ObjectIdsecondCommitExpectedTreeId=newObjectId(expectedShaText);
635647
SignaturesecondCommitAuthorSignature=Constants.Signature;
636648
IdentitysecondCommitCommiterIdentity=Constants.Identity2;
637649

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

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

667-
privatevoidConstructRebaseTestRepository(Repositoryrepo)
679+
privatevoidConstructRebaseTestRepository(Repositoryrepo,stringattributes="* text=auto",stringlineEnding="\r\n")
668680
{
669681
// Constructs a graph that looks like:
670682
// * -- * -- * (modifications to c.txt)
@@ -700,6 +712,11 @@ private void ConstructRebaseTestRepository(Repository repo)
700712
stringworkdir=repo.Info.WorkingDirectory;
701713
Commitcommit=null;
702714

715+
CreateAttributesFile(repo,attributes);
716+
717+
repo.Stage(".gitattributes");
718+
commit=repo.Commit("setup",Constants.Signature,Constants.Signature,newCommitOptions());
719+
703720
Touch(workdir,filePathA,fileContentA1);
704721
repo.Stage(filePathA);
705722
commit=repo.Commit("commit 1",Constants.Signature,Constants.Signature,newCommitOptions());
@@ -714,29 +731,29 @@ private void ConstructRebaseTestRepository(Repository repo)
714731

715732
BranchmasterBranch1=repo.CreateBranch(masterBranch1Name,commit);
716733

717-
Touch(workdir,filePathB,string.Join(Environment.NewLine,fileContentB1,fileContentB2));
734+
Touch(workdir,filePathB,string.Join(lineEnding,fileContentB1,fileContentB2));
718735
repo.Stage(filePathB);
719736
commit=repo.Commit("commit 4",Constants.Signature,Constants.Signature,newCommitOptions());
720737

721-
Touch(workdir,filePathB,string.Join(Environment.NewLine,fileContentB1,fileContentB2,fileContentB3));
738+
Touch(workdir,filePathB,string.Join(lineEnding,fileContentB1,fileContentB2,fileContentB3));
722739
repo.Stage(filePathB);
723740
commit=repo.Commit("commit 5",Constants.Signature,Constants.Signature,newCommitOptions());
724741

725-
Touch(workdir,filePathB,string.Join(Environment.NewLine,fileContentB1,fileContentB2,fileContentB3,fileContentB4));
742+
Touch(workdir,filePathB,string.Join(lineEnding,fileContentB1,fileContentB2,fileContentB3,fileContentB4));
726743
repo.Stage(filePathB);
727744
commit=repo.Commit("commit 6",Constants.Signature,Constants.Signature,newCommitOptions());
728745

729746
repo.CreateBranch(topicBranch1Name,commit);
730747

731-
Touch(workdir,filePathC,string.Join(Environment.NewLine,fileContentC1,fileContentC2));
748+
Touch(workdir,filePathC,string.Join(lineEnding,fileContentC1,fileContentC2));
732749
repo.Stage(filePathC);
733750
commit=repo.Commit("commit 7",Constants.Signature,Constants.Signature,newCommitOptions());
734751

735-
Touch(workdir,filePathC,string.Join(Environment.NewLine,fileContentC1,fileContentC2,fileContentC3));
752+
Touch(workdir,filePathC,string.Join(lineEnding,fileContentC1,fileContentC2,fileContentC3));
736753
repo.Stage(filePathC);
737754
commit=repo.Commit("commit 8",Constants.Signature,Constants.Signature,newCommitOptions());
738755

739-
Touch(workdir,filePathC,string.Join(Environment.NewLine,fileContentC1,fileContentC2,fileContentC3,fileContentC4));
756+
Touch(workdir,filePathC,string.Join(lineEnding,fileContentC1,fileContentC2,fileContentC3,fileContentC4));
740757
repo.Stage(filePathC);
741758
commit=repo.Commit("commit 9",Constants.Signature,Constants.Signature,newCommitOptions());
742759

@@ -747,18 +764,18 @@ private void ConstructRebaseTestRepository(Repository repo)
747764
repo.Stage(filePathD);
748765
commit=repo.Commit("commit 10",Constants.Signature,Constants.Signature,newCommitOptions());
749766

750-
Touch(workdir,filePathD,string.Join(Environment.NewLine,fileContentD1,fileContentD2));
767+
Touch(workdir,filePathD,string.Join(lineEnding,fileContentD1,fileContentD2));
751768
repo.Stage(filePathD);
752769
commit=repo.Commit("commit 11",Constants.Signature,Constants.Signature,newCommitOptions());
753770

754-
Touch(workdir,filePathD,string.Join(Environment.NewLine,fileContentD1,fileContentD2,fileContentD3));
771+
Touch(workdir,filePathD,string.Join(lineEnding,fileContentD1,fileContentD2,fileContentD3));
755772
repo.Stage(filePathD);
756773
commit=repo.Commit("commit 12",Constants.Signature,Constants.Signature,newCommitOptions());
757774

758775
repo.CreateBranch(masterBranch2Name,commit);
759776

760777
// Create commit / branch that conflicts with T1 and T2
761-
Touch(workdir,filePathB,string.Join(Environment.NewLine,fileContentB1,fileContentB2+fileContentB3+fileContentB4));
778+
Touch(workdir,filePathB,string.Join(lineEnding,fileContentB1,fileContentB2+fileContentB3+fileContentB4));
762779
repo.Stage(filePathB);
763780
commit=repo.Commit("commit 13",Constants.Signature,Constants.Signature,newCommitOptions());
764781
repo.CreateBranch(conflictBranch1Name,commit);

‎LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static BaseFixture()
4949
protectedstaticDateTimeOffsetTruncateSubSeconds(DateTimeOffsetdto)
5050
{
5151
intseconds=dto.ToSecondsSinceEpoch();
52-
returnEpoch.ToDateTimeOffset(seconds,(int)dto.Offset.TotalMinutes);
52+
returnEpoch.ToDateTimeOffset(seconds,(int)dto.Offset.TotalMinutes);
5353
}
5454

5555
privatestaticvoidSetUpTestEnvironment()
@@ -258,7 +258,7 @@ protected void RequiresDotNetOrMonoGreaterThanOrEqualTo(System.Version minimumVe
258258
thrownewInvalidOperationException("Cannot access Mono.RunTime.GetDisplayName() method.");
259259
}
260260

261-
varversion=(string)displayName.Invoke(null,null);
261+
varversion=(string)displayName.Invoke(null,null);
262262

263263
System.Versioncurrent;
264264

@@ -460,5 +460,10 @@ public void AssertBelongsToARepository<T>(IRepository repo, T instance)
460460
{
461461
Assert.Same(repo,((IBelongToARepository)instance).Repository);
462462
}
463+
464+
protectedvoidCreateAttributesFile(IRepositoryrepo,stringattributeEntry)
465+
{
466+
Touch(repo.Info.WorkingDirectory,".gitattributes",attributeEntry);
467+
}
463468
}
464469
}

0 commit comments

Comments
(0)