Skip to content

Commit 773d10e

Browse files
committed
Add support for ZDiff3 conflict resolution strategy in merge operations (#1976)
1 parent 50d6978 commit 773d10e

21 files changed

+99
-1
lines changed

LibGit2Sharp.Tests/MergeFixture.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,54 @@ public void CanSpecifyConflictFileStrategy(CheckoutFileConflictStrategy conflict
669669
}
670670
}
671671

672+
[Theory]
673+
[InlineData(CheckoutFileConflictStrategy.Merge)]
674+
[InlineData(CheckoutFileConflictStrategy.Diff3)]
675+
[InlineData(CheckoutFileConflictStrategy.ZDiff3)]
676+
public void CanSpecifyMergeConflictFileStrategy(CheckoutFileConflictStrategy conflictStrategy)
677+
{
678+
const string conflictFile = "a.txt";
679+
const string expectedFileFormat = "a.{0}.txt";
680+
const string conflictBranchName = "conflicts";
681+
const string resultsBranchName = "results";
682+
683+
string expectedFileName = string.Format(expectedFileFormat, conflictStrategy.ToString().ToLower());
684+
string path = SandboxMergeConflictTestRepo();
685+
686+
using (var repo = new Repository(path))
687+
{
688+
Branch branch = repo.Branches[conflictBranchName];
689+
Assert.NotNull(branch);
690+
691+
// Ensure the working directory is clean before merging
692+
repo.Reset(ResetMode.Hard);
693+
repo.RemoveUntrackedFiles();
694+
695+
MergeOptions mergeOptions = new MergeOptions()
696+
{
697+
FileConflictStrategy = conflictStrategy
698+
};
699+
700+
MergeResult result = repo.Merge(branch, Constants.Signature, mergeOptions);
701+
Assert.Equal(MergeStatus.Conflicts, result.Status);
702+
703+
// Get the information on the conflict.
704+
Conflict conflict = repo.Index.Conflicts[conflictFile];
705+
706+
Assert.NotNull(conflict);
707+
Assert.NotNull(conflict.Theirs);
708+
Assert.NotNull(conflict.Ours);
709+
710+
Commit expectedCommit = repo.Branches[resultsBranchName].Tip;
711+
Blob expectedBlob = (Blob)expectedCommit[expectedFileName].Target;
712+
string expectedContent = expectedBlob.GetContentText(new FilteringOptions(expectedFileName));
713+
714+
// Verify the content of the file on disk contains conflict markers.
715+
string fileContent = File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, conflictFile));
716+
Assert.Equal(expectedContent, fileContent);
717+
}
718+
}
719+
672720
[Theory]
673721
[InlineData(MergeFileFavor.Ours)]
674722
[InlineData(MergeFileFavor.Theirs)]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
A
2+
B
3+
C
4+
D
5+
E
6+
F
7+
G
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/main
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = false
4+
bare = false
5+
logallrefupdates = true
6+
ignorecase = true
137 Bytes
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cd4b13da8859445f4357c1e24d92b483ffe2dc85 refs/heads/conflicts
2+
0076e9fe99d1c2df56cd939a897db42d714b088b refs/heads/main
3+
139641856b0ef7941f583972614c1df9bb26939b refs/heads/results
1.32 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
P pack-5fd168964fc34fdc1e4a50ae098e21799dd906a4.pack
2+
P pack-9ea8f8acf571abc3f715ea91223671d542aacb6c.pack
3+
1.43 KB
Binary file not shown.
1.14 KB
Binary file not shown.

0 commit comments

Comments
 (0)