Skip to content

Commit b05a2ea

Browse files
committed
WIP: More rebase testing
1 parent 15c58ec commit b05a2ea

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,74 @@ public void CanRebase(string initialBranchName,
101101
}
102102
}
103103

104+
private class rebaseStepInfo
105+
{
106+
public Commit Commit { get; set; }
107+
}
108+
109+
/// <summary>
110+
/// Verify a single rebase, but in more detail.
111+
/// </summary>
112+
[Fact]
113+
public void VerifyRebaseDetailed()
114+
{
115+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
116+
var path = Repository.Init(scd.DirectoryPath);
117+
118+
using (Repository repo = new Repository(path))
119+
{
120+
ConstructRebaseTestRepository(repo);
121+
122+
Branch initialBranch = repo.Branches[topicBranch1Name];
123+
Branch upstreamBranch = repo.Branches[masterBranch2Name];
124+
125+
repo.Checkout(initialBranch);
126+
Assert.False(repo.RetrieveStatus().IsDirty);
127+
128+
bool wasCheckoutProgressCalled = false;
129+
bool wasCheckoutNotifyCalled = false;
130+
131+
RebaseOptions options = new RebaseOptions()
132+
{
133+
OnCheckoutProgress = (x, y, z) => wasCheckoutProgressCalled = true,
134+
OnCheckoutNotify = (x, y) => { wasCheckoutNotifyCalled = true; return true; },
135+
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated,
136+
};
137+
138+
repo.Rebase.Start(null, upstreamBranch, null, Constants.Signature2, options);
139+
140+
Assert.Equal(true, wasCheckoutNotifyCalled);
141+
Assert.Equal(true, wasCheckoutProgressCalled);
142+
143+
// Verify the chain of resultant rebased commits.
144+
CommitFilter commitFilter = new CommitFilter()
145+
{
146+
Since = repo.Head.Tip,
147+
Until = upstreamBranch.Tip,
148+
SortBy = CommitSortStrategies.Reverse | CommitSortStrategies.Topological,
149+
};
150+
151+
List<ObjectId> expectedTreeIds = new List<ObjectId>()
152+
{
153+
new ObjectId("447bad85bcc1882037848370620a6f88e8ee264e"),
154+
new ObjectId("3b0fc846952496a64b6149064cde21215daca8f8"),
155+
new ObjectId("a2d114246012daf3ef8e7ccbfbe91889a24e1e60"),
156+
};
157+
158+
List<Commit> rebasedCommits = repo.Commits.QueryBy(commitFilter).ToList();
159+
160+
Assert.Equal(3, rebasedCommits.Count);
161+
for(int i = 0; i < 3; i++)
162+
{
163+
Assert.Equal(expectedTreeIds[i], rebasedCommits[i].Tree.Id);
164+
Assert.Equal(Constants.Signature.Name, rebasedCommits[i].Author.Name);
165+
Assert.Equal(Constants.Signature.Email, rebasedCommits[i].Author.Email);
166+
Assert.Equal(Constants.Signature2.Name, rebasedCommits[i].Committer.Name);
167+
Assert.Equal(Constants.Signature2.Email, rebasedCommits[i].Committer.Email);
168+
}
169+
}
170+
}
171+
104172
[Fact]
105173
public void CanContinueRebase()
106174
{
@@ -119,10 +187,16 @@ public void CanContinueRebase()
119187

120188
int beforeStepCallCount = 0;
121189
int afterStepCallCount = 0;
190+
bool wasCheckoutProgressCalled = false;
191+
bool wasCheckoutNotifyCalled = false;
192+
122193
RebaseOptions options = new RebaseOptions()
123194
{
124195
RebaseStepStarting = x => beforeStepCallCount++,
125196
RebaseStepCompleted = x => afterStepCallCount++,
197+
OnCheckoutProgress = (x, y, z) => wasCheckoutProgressCalled = true,
198+
OnCheckoutNotify = (x, y) => { wasCheckoutNotifyCalled = true; return true; },
199+
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated | CheckoutNotifyFlags.Conflict,
126200
};
127201

128202
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Signature, options);
@@ -135,8 +209,13 @@ public void CanContinueRebase()
135209
Assert.Equal(0, rebaseResult.CompletedStepCount);
136210
Assert.Equal(3, rebaseResult.TotalStepCount);
137211

212+
// Verify that expected callbacks were called
138213
Assert.Equal(1, beforeStepCallCount);
139214
Assert.Equal(0, afterStepCallCount);
215+
Assert.True(wasCheckoutProgressCalled, "CheckoutProgress callback was not called.");
216+
217+
// TODO: investigate following statement.
218+
// Assert.True(wasCheckoutNotifyCalled, "CheckoutNotify callback was not called.");
140219

141220
// Resolve the conflict
142221
foreach (Conflict conflict in repo.Index.Conflicts)
@@ -149,6 +228,8 @@ public void CanContinueRebase()
149228

150229
Assert.True(repo.Index.IsFullyMerged);
151230

231+
// Clear the flags:
232+
wasCheckoutProgressCalled = false; wasCheckoutNotifyCalled = false;
152233
RebaseResult continuedRebaseResult = repo.Rebase.Continue(Constants.Signature, options);
153234

154235
Assert.NotNull(continuedRebaseResult);
@@ -160,8 +241,8 @@ public void CanContinueRebase()
160241

161242
Assert.Equal(3, beforeStepCallCount);
162243
Assert.Equal(3, afterStepCallCount);
163-
164-
// TODO: Validate the expected HEAD commit ID
244+
Assert.True(wasCheckoutProgressCalled, "CheckoutProgress callback was not called.");
245+
Assert.True(wasCheckoutNotifyCalled, "CheckoutNotify callback was not called.");
165246
}
166247
}
167248

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static class Constants
77
public const string TemporaryReposPath = "TestRepos";
88
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
99
public static readonly Signature Signature = new Signature("A. U. Thor", "thor@valhalla.asgard.com", new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
10+
public static readonly Signature Signature2 = new Signature("nulltoken", "emeric.fermas@gmail.com", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
1011

1112
// Populate these to turn on live credential tests: set the
1213
// PrivateRepoUrl to the URL of a repository that requires

0 commit comments

Comments
 (0)