Skip to content

Commit 334f2c6

Browse files
committed
Verify that attempting to continue a rebase with unstaged changes throws.
1 parent 8bfea83 commit 334f2c6

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public class RebaseFixture : BaseFixture
1616
const string conflictBranch1Name = "C1";
1717
const string topicBranch1PrimeName = "T1Prime";
1818

19+
string filePathA = "a.txt";
20+
string filePathB = "b.txt";
21+
string filePathC = "c.txt";
22+
string filePathD = "d.txt";
23+
1924
[Theory]
2025
[InlineData(topicBranch2Name, topicBranch2Name, topicBranch1Name, masterBranch1Name, 3)]
2126
[InlineData(topicBranch2Name, topicBranch2Name, topicBranch1Name, topicBranch1Name, 3)]
@@ -310,9 +315,6 @@ public void CanContinueRebase()
310315
Assert.Equal(0, afterStepCallCount);
311316
Assert.True(wasCheckoutProgressCalled, "CheckoutProgress callback was not called.");
312317

313-
// TODO: investigate following statement.
314-
// Assert.True(wasCheckoutNotifyCalled, "CheckoutNotify callback was not called.");
315-
316318
// Resolve the conflict
317319
foreach (Conflict conflict in repo.Index.Conflicts)
318320
{
@@ -342,6 +344,55 @@ public void CanContinueRebase()
342344
}
343345
}
344346

347+
[Fact]
348+
public void ContinuingRebaseWithUnstagedChangesThrows()
349+
{
350+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
351+
var path = Repository.Init(scd.DirectoryPath);
352+
using (Repository repo = new Repository(path))
353+
{
354+
ConstructRebaseTestRepository(repo);
355+
356+
repo.Checkout(topicBranch1Name);
357+
Assert.False(repo.RetrieveStatus().IsDirty);
358+
359+
Branch branch = repo.Branches[topicBranch1Name];
360+
Branch upstream = repo.Branches[conflictBranch1Name];
361+
Branch onto = repo.Branches[conflictBranch1Name];
362+
363+
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Identity, null);
364+
365+
// Verify that we have a conflict.
366+
Assert.Equal(CurrentOperation.RebaseMerge, repo.Info.CurrentOperation);
367+
Assert.Equal(RebaseStatus.Conflicts, rebaseResult.Status);
368+
Assert.True(repo.RetrieveStatus().IsDirty);
369+
Assert.False(repo.Index.IsFullyMerged);
370+
Assert.Equal(0, rebaseResult.CompletedStepCount);
371+
Assert.Equal(3, rebaseResult.TotalStepCount);
372+
373+
Assert.Throws<UnmergedIndexEntriesException>(() =>
374+
repo.Rebase.Continue(Constants.Identity, null));
375+
376+
// Resolve the conflict
377+
foreach (Conflict conflict in repo.Index.Conflicts)
378+
{
379+
Touch(repo.Info.WorkingDirectory,
380+
conflict.Theirs.Path,
381+
repo.Lookup<Blob>(conflict.Theirs.Id).GetContentText(new FilteringOptions(conflict.Theirs.Path)));
382+
repo.Stage(conflict.Theirs.Path);
383+
}
384+
385+
Touch(repo.Info.WorkingDirectory,
386+
filePathA,
387+
"Unstaged content");
388+
389+
Assert.Throws<UnmergedIndexEntriesException>(() =>
390+
repo.Rebase.Continue(Constants.Identity, null));
391+
392+
Assert.True(repo.Index.IsFullyMerged);
393+
}
394+
}
395+
345396
[Fact]
346397
public void CanQueryRebaseOperation()
347398
{
@@ -571,22 +622,18 @@ private void ConstructRebaseTestRepository(Repository repo)
571622
// ---*
572623
// |
573624
// C1
574-
string filePathA = "a.txt";
575625
const string fileContentA1 = "A1";
576626

577-
string filePathB = "b.txt";
578627
const string fileContentB1 = "B1";
579628
const string fileContentB2 = "B2";
580629
const string fileContentB3 = "B3";
581630
const string fileContentB4 = "B4";
582631

583-
string filePathC = "c.txt";
584632
const string fileContentC1 = "C1";
585633
const string fileContentC2 = "C2";
586634
const string fileContentC3 = "C3";
587635
const string fileContentC4 = "C4";
588636

589-
string filePathD = "d.txt";
590637
const string fileContentD1 = "D1";
591638
const string fileContentD2 = "D2";
592639
const string fileContentD3 = "D3";

0 commit comments

Comments
 (0)