Example #1
0
        public virtual void TestMergeConflictFileFolder()
        {
            Git git = new Git(db);

            WriteTrashFile("a", "1\na\n3\n");
            WriteTrashFile("b", "1\nb\n3\n");
            git.Add().AddFilepattern("a").AddFilepattern("b").Call();
            RevCommit initialCommit = git.Commit().SetMessage("initial").Call();

            CreateBranch(initialCommit, "refs/heads/side");
            CheckoutBranch("refs/heads/side");
            WriteTrashFile("c/c/c", "1\nc(side)\n3\n");
            WriteTrashFile("d", "1\nd(side)\n3\n");
            git.Add().AddFilepattern("c/c/c").AddFilepattern("d").Call();
            RevCommit secondCommit = git.Commit().SetMessage("side").Call();

            CheckoutBranch("refs/heads/master");
            WriteTrashFile("c", "1\nc(main)\n3\n");
            WriteTrashFile("d/d/d", "1\nd(main)\n3\n");
            git.Add().AddFilepattern("c").AddFilepattern("d/d/d").Call();
            git.Commit().SetMessage("main").Call();
            MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
                                                                                         .RESOLVE).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
            NUnit.Framework.Assert.AreEqual("1\na\n3\n", Read(new FilePath(db.WorkTree, "a"))
                                            );
            NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b"))
                                            );
            NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree,
                                                                                 "c")));
            NUnit.Framework.Assert.AreEqual("1\nd(main)\n3\n", Read(new FilePath(db.WorkTree,
                                                                                 "d/d/d")));
            NUnit.Framework.Assert.AreEqual(null, result.GetConflicts());
            NUnit.Framework.Assert.AreEqual(RepositoryState.MERGING, db.GetRepositoryState());
        }
Example #2
0
        public virtual void TestMergeFailingWithDirtyWorkingTree()
        {
            Git git = new Git(db);

            WriteTrashFile("a", "1\na\n3\n");
            WriteTrashFile("b", "1\nb\n3\n");
            git.Add().AddFilepattern("a").AddFilepattern("b").Call();
            RevCommit initialCommit = git.Commit().SetMessage("initial").Call();

            CreateBranch(initialCommit, "refs/heads/side");
            CheckoutBranch("refs/heads/side");
            WriteTrashFile("a", "1(side)\na\n3\n");
            WriteTrashFile("b", "1\nb(side)\n3\n");
            git.Add().AddFilepattern("a").AddFilepattern("b").Call();
            RevCommit secondCommit = git.Commit().SetMessage("side").Call();

            NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree,
                                                                                 "b")));
            CheckoutBranch("refs/heads/master");
            NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b"))
                                            );
            WriteTrashFile("a", "1\na\n3(main)\n");
            git.Add().AddFilepattern("a").Call();
            git.Commit().SetMessage("main").Call();
            WriteTrashFile("a", "--- dirty ---");
            MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
                                                                                         .RESOLVE).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.FAILED, result.GetMergeStatus());
            NUnit.Framework.Assert.AreEqual("--- dirty ---", Read(new FilePath(db.WorkTree, "a"
                                                                               )));
            NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b"))
                                            );
            NUnit.Framework.Assert.AreEqual(null, result.GetConflicts());
            NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState());
        }