Skip to content

Commit 15c58ec

Browse files
committed
WIP: Improve rebase test coverage
1 parent 5319f11 commit 15c58ec

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public class RebaseFixture : BaseFixture
2424
[InlineData(topicBranch2Name, topicBranch1Name, masterBranch2Name, masterBranch2Name, 3)]
2525
[InlineData(topicBranch2Name, topicBranch1Name, masterBranch2Name, null, 3)]
2626
[InlineData(topicBranch1Name, null, masterBranch2Name, null, 3)]
27-
public void CanRebase(string initialBranchName, string branchName, string upstreamName, string ontoName, int stepCount)
27+
public void CanRebase(string initialBranchName,
28+
string branchName,
29+
string upstreamName,
30+
string ontoName,
31+
int stepCount)
2832
{
2933
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
3034
var path = Repository.Init(scd.DirectoryPath);
@@ -36,15 +40,31 @@ public void CanRebase(string initialBranchName, string branchName, string upstre
3640
Assert.False(repo.RetrieveStatus().IsDirty);
3741

3842
Branch branch = (branchName == null) ? null : repo.Branches[branchName];
39-
Branch upstream = (upstreamName == null) ? null : repo.Branches[upstreamName];
43+
Branch upstream = repo.Branches[upstreamName];
4044
Branch onto = (ontoName == null) ? null : repo.Branches[ontoName];
45+
Commit expectedSinceCommit = (branch == null) ? repo.Head.Tip : branch.Tip;
46+
Commit expectedUntilCommit = upstream.Tip;
47+
Commit expectedOntoCommit = (onto == null) ? upstream.Tip : onto.Tip;
4148

4249
int beforeStepCallCount = 0;
4350
int afterStepCallCount = 0;
51+
52+
List<ObjectId> PreRebaseCommits = new List<ObjectId>();
53+
List<ObjectId> PostRebaseCommits = new List<ObjectId>();
54+
ObjectId expectedParentId = upstream.Tip.Id;
55+
4456
RebaseOptions options = new RebaseOptions()
4557
{
46-
RebaseStepStarting = x => beforeStepCallCount++,
47-
RebaseStepCompleted = x => afterStepCallCount++,
58+
RebaseStepStarting = x =>
59+
{
60+
beforeStepCallCount++;
61+
PreRebaseCommits.Add(x.StepInfo.ID);
62+
},
63+
RebaseStepCompleted = x =>
64+
{
65+
afterStepCallCount++;
66+
PostRebaseCommits.Add(x.CommitId);
67+
},
4868
};
4969

5070
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Signature, options);
@@ -60,7 +80,24 @@ public void CanRebase(string initialBranchName, string branchName, string upstre
6080
Assert.Equal(stepCount, beforeStepCallCount);
6181
Assert.Equal(stepCount, afterStepCallCount);
6282

63-
// TODO: Validate the expected HEAD commit ID
83+
// Verify the chain of source commits that were rebased.
84+
CommitFilter sourceCommitFilter = new CommitFilter()
85+
{
86+
Since = expectedSinceCommit,
87+
Until = expectedUntilCommit,
88+
SortBy = CommitSortStrategies.Reverse | CommitSortStrategies.Topological,
89+
};
90+
Assert.Equal(repo.Commits.QueryBy(sourceCommitFilter).Select(c => c.Id), PreRebaseCommits);
91+
92+
// Verify the chain of commits that resulted from the rebase.
93+
Commit expectedParent = expectedOntoCommit;
94+
foreach(Commit rebasedCommit in PostRebaseCommits.Select(id => repo.Lookup<Commit>(id)))
95+
{
96+
Assert.Equal(expectedParent.Id, rebasedCommit.Parents.First().Id);
97+
expectedParent = rebasedCommit;
98+
}
99+
100+
Assert.Equal(repo.Head.Tip.Id, PostRebaseCommits.Last());
64101
}
65102
}
66103

0 commit comments

Comments
 (0)