Skip to content

Commit 6182cb4

Browse files
committed
Rebase abort should support options parameter
1 parent 0cff6b0 commit 6182cb4

File tree

3 files changed

+75
-17
lines changed

3 files changed

+75
-17
lines changed

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,48 @@ public void VerifyRebaseDetailed()
191191
Assert.False(repo.RetrieveStatus().IsDirty);
192192

193193
bool wasCheckoutProgressCalled = false;
194+
bool wasCheckoutProgressCalledForResetingHead = false;
194195
bool wasCheckoutNotifyCalled = false;
196+
bool wasCheckoutNotifyCalledForResetingHead = false;
197+
198+
bool startedApplyingSteps = false;
195199

196200
RebaseOptions options = new RebaseOptions()
197201
{
198-
OnCheckoutProgress = (x, y, z) => wasCheckoutProgressCalled = true,
199-
OnCheckoutNotify = (x, y) => { wasCheckoutNotifyCalled = true; return true; },
202+
OnCheckoutProgress = (x, y, z) =>
203+
{
204+
if (startedApplyingSteps)
205+
{
206+
wasCheckoutProgressCalled = true;
207+
}
208+
else
209+
{
210+
wasCheckoutProgressCalledForResetingHead = true;
211+
}
212+
},
213+
OnCheckoutNotify = (x, y) =>
214+
{
215+
if (startedApplyingSteps)
216+
{
217+
wasCheckoutNotifyCalled = true;
218+
}
219+
else
220+
{
221+
wasCheckoutNotifyCalledForResetingHead = true;
222+
}
223+
224+
return true;
225+
},
200226
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated,
227+
228+
RebaseStepStarting = x => startedApplyingSteps = true,
229+
201230
};
202231

203232
repo.Rebase.Start(null, upstreamBranch, null, Constants.Signature2, options);
204233

234+
Assert.Equal(true, wasCheckoutNotifyCalledForResetingHead);
235+
Assert.Equal(true, wasCheckoutProgressCalledForResetingHead);
205236
Assert.Equal(true, wasCheckoutNotifyCalled);
206237
Assert.Equal(true, wasCheckoutProgressCalled);
207238

@@ -261,7 +292,7 @@ public void CanContinueRebase()
261292
RebaseStepCompleted = x => afterStepCallCount++,
262293
OnCheckoutProgress = (x, y, z) => wasCheckoutProgressCalled = true,
263294
OnCheckoutNotify = (x, y) => { wasCheckoutNotifyCalled = true; return true; },
264-
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated | CheckoutNotifyFlags.Conflict,
295+
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated,
265296
};
266297

267298
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Signature, options);
@@ -368,10 +399,24 @@ public void CanAbortRebase()
368399
Assert.Equal(0, rebaseResult.CompletedStepCount);
369400
Assert.Equal(3, rebaseResult.TotalStepCount);
370401

371-
repo.Rebase.Abort();
372-
Assert.False(repo.RetrieveStatus().IsDirty);
373-
Assert.True(repo.Index.IsFullyMerged);
402+
// Set up the callbacks to verify that checkout progress / notify
403+
// callbacks are called.
404+
bool wasCheckoutProgressCalled = false;
405+
bool wasCheckoutNotifyCalled = false;
406+
RebaseOptions options = new RebaseOptions()
407+
{
408+
OnCheckoutProgress = (x, y, z) => wasCheckoutProgressCalled = true,
409+
OnCheckoutNotify = (x, y) => { wasCheckoutNotifyCalled = true; return true; },
410+
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated,
411+
};
412+
413+
repo.Rebase.Abort(options);
414+
Assert.False(repo.RetrieveStatus().IsDirty, "Repository workdir is dirty after Rebase.Abort.");
415+
Assert.True(repo.Index.IsFullyMerged, "Repository index is not fully merged after Rebase.Abort.");
374416
Assert.Equal(CurrentOperation.None, repo.Info.CurrentOperation);
417+
418+
Assert.True(wasCheckoutProgressCalled, "Checkout progress callback was not called during Rebase.Abort.");
419+
Assert.True(wasCheckoutNotifyCalled, "Checkout notify callback was not called during Rebase.Abort.");
375420
}
376421
}
377422

LibGit2Sharp/Rebase.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ internal Rebase(Repository repo)
7070
/// <param name="branch">The branch to rebase.</param>
7171
/// <param name="upstream">The starting commit to rebase.</param>
7272
/// <param name="onto">The branch to rebase onto.</param>
73-
/// <param name="committer"></param>
74-
/// <param name="options"></param>
73+
/// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
74+
/// <param name="options">The <see cref="RebaseOptions"/> that specify the rebase behavior.</param>
7575
/// <returns>true if completed successfully, false if conflicts encountered.</returns>
7676
public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, Signature committer, RebaseOptions options)
7777
{
@@ -133,7 +133,7 @@ public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, S
133133
/// Continue the current rebase.
134134
/// </summary>
135135
/// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
136-
/// <param name="options">The <see cref="RebaseOptions"/> that specify the commit behavior.</param>
136+
/// <param name="options">The <see cref="RebaseOptions"/> that specify the rebase behavior.</param>
137137
public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
138138
{
139139
Ensure.ArgumentNotNull(committer, "committer");
@@ -190,11 +190,28 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
190190
/// </summary>
191191
public virtual void Abort()
192192
{
193-
GitRebaseOptions gitRebaseOptions = new GitRebaseOptions();
193+
Abort(null);
194+
}
194195

195-
using (RebaseSafeHandle rebase = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
196+
/// <summary>
197+
/// Abort the rebase operation.
198+
/// </summary>
199+
/// <param name="options">The <see cref="RebaseOptions"/> that specify the rebase behavior.</param>
200+
public virtual void Abort(RebaseOptions options)
201+
{
202+
options = options ?? new RebaseOptions();
203+
204+
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
196205
{
197-
Proxy.git_rebase_abort(rebase);
206+
GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
207+
{
208+
checkout_options = checkoutOptionsWrapper.Options,
209+
};
210+
211+
using (RebaseSafeHandle rebase = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
212+
{
213+
Proxy.git_rebase_abort(rebase);
214+
}
198215
}
199216
}
200217

LibGit2Sharp/RebaseOptions.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using LibGit2Sharp.Core;
1+
using LibGit2Sharp.Core;
62
using LibGit2Sharp.Handlers;
73

84
namespace LibGit2Sharp

0 commit comments

Comments
 (0)