public void CanMergeIntoIndexWithConflicts() { string path = SandboxMergeTestRepo(); using (var repo = new Repository(path)) { var master = repo.Lookup <Commit>("master"); var branch = repo.Lookup <Commit>("conflicts"); using (TransientIndex index = repo.ObjectDatabase.MergeCommitsIntoIndex(branch, master, null)) { Assert.False(index.IsFullyMerged); var conflict = index.Conflicts.First(); //Resolve the conflict by taking the blob from branch var blob = repo.Lookup <Blob>(conflict.Ours.Id); //Add() does not remove conflict entries for the same path, so they must be explicitly removed first. index.Remove(conflict.Ours.Path); index.Add(blob, conflict.Ours.Path, Mode.NonExecutableFile); Assert.True(index.IsFullyMerged); var tree = index.WriteToTree(); //Since we took the conflicted blob from the branch, the merged result should be the same as the branch. Assert.Equal(branch.Tree.Id, tree.Id); } } }
public void CanCherryPickIntoIndexWithConflicts() { const string conflictBranchName = "conflicts"; string path = SandboxMergeTestRepo(); using (var repo = new Repository(path)) { Branch branch = repo.Branches[conflictBranchName]; Assert.NotNull(branch); using (TransientIndex index = repo.ObjectDatabase.CherryPickCommitIntoIndex(branch.Tip, repo.Head.Tip, 0, null)) { Assert.False(index.IsFullyMerged); var conflict = index.Conflicts.First(); //Resolve the conflict by taking the blob from branch var blob = repo.Lookup <Blob>(conflict.Theirs.Id); //Add() does not remove conflict entries for the same path, so they must be explicitly removed first. index.Remove(conflict.Ours.Path); index.Add(blob, conflict.Ours.Path, Mode.NonExecutableFile); Assert.True(index.IsFullyMerged); var tree = index.WriteToTree(); //Since we took the conflicted blob from the branch, the merged result should be the same as the branch. Assert.Equal(branch.Tip.Tree.Id, tree.Id); } } }