Skip to content

Commit 6b17d38

Browse files
committed
Verify that we can specify FileConflictStrategy when rebasing
1 parent 03cf4c2 commit 6b17d38

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using LibGit2Sharp.Tests.TestHelpers;
55
using Xunit;
66
using Xunit.Extensions;
7+
using System.IO;
78

89
namespace LibGit2Sharp.Tests
910
{
@@ -393,6 +394,53 @@ public void ContinuingRebaseWithUnstagedChangesThrows()
393394
}
394395
}
395396

397+
[Fact]
398+
public void CanSpecifyFileConflictStrategy()
399+
{
400+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
401+
var path = Repository.Init(scd.DirectoryPath);
402+
using (Repository repo = new Repository(path))
403+
{
404+
ConstructRebaseTestRepository(repo);
405+
406+
repo.Checkout(topicBranch1Name);
407+
Assert.False(repo.RetrieveStatus().IsDirty);
408+
409+
Branch branch = repo.Branches[topicBranch1Name];
410+
Branch upstream = repo.Branches[conflictBranch1Name];
411+
Branch onto = repo.Branches[conflictBranch1Name];
412+
413+
RebaseOptions options = new RebaseOptions()
414+
{
415+
FileConflictStrategy = CheckoutFileConflictStrategy.Ours,
416+
};
417+
418+
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Identity, options);
419+
420+
// Verify that we have a conflict.
421+
Assert.Equal(CurrentOperation.RebaseMerge, repo.Info.CurrentOperation);
422+
Assert.Equal(RebaseStatus.Conflicts, rebaseResult.Status);
423+
Assert.True(repo.RetrieveStatus().IsDirty);
424+
Assert.False(repo.Index.IsFullyMerged);
425+
Assert.Equal(0, rebaseResult.CompletedStepCount);
426+
Assert.Equal(3, rebaseResult.TotalStepCount);
427+
428+
string conflictFile = filePathB;
429+
// Get the information on the conflict.
430+
Conflict conflict = repo.Index.Conflicts[conflictFile];
431+
432+
Assert.NotNull(conflict);
433+
Assert.NotNull(conflict.Theirs);
434+
Assert.NotNull(conflict.Ours);
435+
436+
Blob expectedBlob = repo.Lookup<Blob>(conflict.Ours.Id);
437+
438+
// Check the content of the file on disk matches what is expected.
439+
string expectedContent = expectedBlob.GetContentText(new FilteringOptions(conflictFile));
440+
Assert.Equal(expectedContent, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, conflictFile)));
441+
}
442+
}
443+
396444
[Fact]
397445
public void CanQueryRebaseOperation()
398446
{

0 commit comments

Comments
 (0)