|
4 | 4 | using LibGit2Sharp.Tests.TestHelpers;
|
5 | 5 | using Xunit;
|
6 | 6 | using Xunit.Extensions;
|
| 7 | +using System.IO; |
7 | 8 |
|
8 | 9 | namespace LibGit2Sharp.Tests
|
9 | 10 | {
|
@@ -393,6 +394,53 @@ public void ContinuingRebaseWithUnstagedChangesThrows()
|
393 | 394 | }
|
394 | 395 | }
|
395 | 396 |
|
| 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 | + |
396 | 444 | [Fact]
|
397 | 445 | public void CanQueryRebaseOperation()
|
398 | 446 | {
|
|
0 commit comments