Skip to content

Commit 2fada18

Browse files
Evgeny Trifonovethomson
Evgeny Trifonov
authored andcommitted
Added IgnoreWhitespaceChange option to MergeOptions;
1 parent 2e3238f commit 2fada18

12 files changed

+49
-0
lines changed

LibGit2Sharp.Tests/MergeFixture.cs

+37
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,43 @@ public void CanIdentifyConflictsInMergeCommits()
865865
}
866866
}
867867

868+
[Theory]
869+
[InlineData("conflicts_spaces")]
870+
[InlineData("conflicts_tabs")]
871+
public void CanConflictOnWhitespaceChangeMergeConflict(string branchName)
872+
{
873+
string path = SandboxMergeTestRepo();
874+
using (var repo = new Repository(path))
875+
{
876+
var mergeResult = repo.Merge(branchName, Constants.Signature, new MergeOptions());
877+
Assert.Equal(MergeStatus.Conflicts, mergeResult.Status);
878+
879+
var master = repo.Branches["master"];
880+
var branch = repo.Branches[branchName];
881+
var mergeTreeResult = repo.ObjectDatabase.MergeCommits(master.Tip, branch.Tip, new MergeTreeOptions());
882+
Assert.Equal(MergeTreeStatus.Conflicts, mergeTreeResult.Status);
883+
}
884+
}
885+
886+
[Theory]
887+
[InlineData("conflicts_spaces")]
888+
[InlineData("conflicts_tabs")]
889+
public void CanIgnoreWhitespaceChangeMergeConflict(string branchName)
890+
{
891+
string path = SandboxMergeTestRepo();
892+
using (var repo = new Repository(path))
893+
{
894+
var mergeResult = repo.Merge(branchName, Constants.Signature, new MergeOptions() { IgnoreWhitespaceChange = true });
895+
Assert.NotEqual(MergeStatus.Conflicts, mergeResult.Status);
896+
897+
var master = repo.Branches["master"];
898+
var branch = repo.Branches[branchName];
899+
var mergeTreeResult = repo.ObjectDatabase.MergeCommits(master.Tip, branch.Tip, new MergeTreeOptions() { IgnoreWhitespaceChange = true });
900+
Assert.NotEqual(MergeTreeStatus.Conflicts, mergeTreeResult.Status);
901+
Assert.Empty(mergeTreeResult.Conflicts);
902+
}
903+
}
904+
868905
private Commit AddFileCommitToRepo(IRepository repository, string filename, string content = null)
869906
{
870907
Touch(repository.Info.WorkingDirectory, filename, content);
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
79853dbb13f5e83a1e9e69bf747c5a667c21d420
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e55b31220c73a5535ba58709791880f3035849d4

LibGit2Sharp/MergeOptionsBase.cs

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ protected MergeOptionsBase()
5050
/// How to handle conflicts encountered during a merge.
5151
/// </summary>
5252
public MergeFileFavor MergeFileFavor { get; set; }
53+
54+
/// <summary>
55+
/// Ignore changes in amount of whitespace
56+
/// </summary>
57+
public bool IgnoreWhitespaceChange { get; set; }
5358
}
5459

5560
/// <summary>

LibGit2Sharp/Repository.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1533,13 +1533,18 @@ private MergeResult NormalMerge(AnnotatedCommitHandle[] annotatedCommits, Signat
15331533
treeFlags |= GitMergeFlag.GIT_MERGE_SKIP_REUC;
15341534
}
15351535

1536+
var fileFlags = options.IgnoreWhitespaceChange
1537+
? GitMergeFileFlag.GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE
1538+
: GitMergeFileFlag.GIT_MERGE_FILE_DEFAULT;
1539+
15361540
var mergeOptions = new GitMergeOpts
15371541
{
15381542
Version = 1,
15391543
MergeFileFavorFlags = options.MergeFileFavor,
15401544
MergeTreeFlags = treeFlags,
15411545
RenameThreshold = (uint)options.RenameThreshold,
15421546
TargetLimit = (uint)options.TargetLimit,
1547+
FileFlags = fileFlags
15431548
};
15441549

15451550
bool earlyStop;

0 commit comments

Comments
 (0)