예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
        public void CanMergeIntoIndex()
        {
            string path = SandboxMergeTestRepo();

            using (var repo = new Repository(path))
            {
                var master = repo.Lookup <Commit>("master");

                using (TransientIndex index = repo.ObjectDatabase.MergeCommitsIntoIndex(master, master, null))
                {
                    var tree = index.WriteToTree();
                    Assert.Equal(master.Tree.Id, tree.Id);
                }
            }
        }
예제 #4
0
        public void CanCherryPickCommitIntoIndex()
        {
            string path = SandboxMergeTestRepo();

            using (var repo = new Repository(path))
            {
                var ours = repo.Head.Tip;

                Commit commitToMerge = repo.Branches["fast_forward"].Tip;

                using (TransientIndex index = repo.ObjectDatabase.CherryPickCommitIntoIndex(commitToMerge, ours, 0, null))
                {
                    var tree = index.WriteToTree();
                    Assert.Equal(commitToMerge.Tree.Id, tree.Id);
                }
            }
        }