@@ -24,7 +24,11 @@ public class RebaseFixture : BaseFixture
24
24
[ InlineData ( topicBranch2Name , topicBranch1Name , masterBranch2Name , masterBranch2Name , 3 ) ]
25
25
[ InlineData ( topicBranch2Name , topicBranch1Name , masterBranch2Name , null , 3 ) ]
26
26
[ 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 )
28
32
{
29
33
SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
30
34
var path = Repository . Init ( scd . DirectoryPath ) ;
@@ -36,15 +40,31 @@ public void CanRebase(string initialBranchName, string branchName, string upstre
36
40
Assert . False ( repo . RetrieveStatus ( ) . IsDirty ) ;
37
41
38
42
Branch branch = ( branchName == null ) ? null : repo . Branches [ branchName ] ;
39
- Branch upstream = ( upstreamName == null ) ? null : repo . Branches [ upstreamName ] ;
43
+ Branch upstream = repo . Branches [ upstreamName ] ;
40
44
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 ;
41
48
42
49
int beforeStepCallCount = 0 ;
43
50
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
+
44
56
RebaseOptions options = new RebaseOptions ( )
45
57
{
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
+ } ,
48
68
} ;
49
69
50
70
RebaseResult rebaseResult = repo . Rebase . Start ( branch , upstream , onto , Constants . Signature , options ) ;
@@ -60,7 +80,24 @@ public void CanRebase(string initialBranchName, string branchName, string upstre
60
80
Assert . Equal ( stepCount , beforeStepCallCount ) ;
61
81
Assert . Equal ( stepCount , afterStepCallCount ) ;
62
82
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 ( ) ) ;
64
101
}
65
102
}
66
103
0 commit comments