Esempio n. 1
0
        public virtual void TestFastForwardWithFiles()
        {
            Git git = new Git(db);

            WriteTrashFile("file1", "file1");
            git.Add().AddFilepattern("file1").Call();
            RevCommit first = git.Commit().SetMessage("initial commit").Call();

            NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file1").Exists());
            CreateBranch(first, "refs/heads/branch1");
            WriteTrashFile("file2", "file2");
            git.Add().AddFilepattern("file2").Call();
            RevCommit second = git.Commit().SetMessage("second commit").Call();

            NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
            CheckoutBranch("refs/heads/branch1");
            NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "file2").Exists());
            MergeCommandResult result = git.Merge().Include(db.GetRef(Constants.MASTER)).Call
                                            ();

            NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file1").Exists());
            NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
            NUnit.Framework.Assert.AreEqual(MergeStatus.FAST_FORWARD, result.GetMergeStatus()
                                            );
            NUnit.Framework.Assert.AreEqual(second, result.GetNewHead());
        }
        public virtual void TestPullMerge()
        {
            PullResult res = target.Pull().Call();

            // nothing to update since we don't have different data yet
            NUnit.Framework.Assert.IsTrue(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty
                                              ());
            NUnit.Framework.Assert.IsTrue(res.GetMergeResult().GetMergeStatus().Equals(MergeStatus
                                                                                       .ALREADY_UP_TO_DATE));
            WriteToFile(sourceFile, "Source change");
            source.Add().AddFilepattern("SomeFile.txt");
            RevCommit sourceCommit = source.Commit().SetMessage("Source change in remote").Call
                                         ();
            FilePath targetFile2 = new FilePath(dbTarget.WorkTree, "OtherFile.txt");

            WriteToFile(targetFile2, "Unconflicting change");
            target.Add().AddFilepattern("OtherFile.txt").Call();
            RevCommit targetCommit = target.Commit().SetMessage("Unconflicting change in local"
                                                                ).Call();

            res = target.Pull().Call();
            MergeCommandResult mergeResult = res.GetMergeResult();

            ObjectId[] mergedCommits = mergeResult.GetMergedCommits();
            NUnit.Framework.Assert.AreEqual(targetCommit.Id, mergedCommits[0]);
            NUnit.Framework.Assert.AreEqual(sourceCommit.Id, mergedCommits[1]);
            RevCommit mergeCommit = new RevWalk(dbTarget).ParseCommit(mergeResult.GetNewHead(
                                                                          ));
            string message = "Merge branch 'master' of " + db.WorkTree;

            NUnit.Framework.Assert.AreEqual(message, mergeCommit.GetShortMessage());
        }
Esempio n. 3
0
        public virtual void TestSuccessfulContentMergeAndDirtyworkingTree()
        {
            Git git = new Git(db);

            WriteTrashFile("a", "1\na\n3\n");
            WriteTrashFile("b", "1\nb\n3\n");
            WriteTrashFile("d", "1\nd\n3\n");
            WriteTrashFile("c/c/c", "1\nc\n3\n");
            git.Add().AddFilepattern("a").AddFilepattern("b").AddFilepattern("c/c/c").AddFilepattern
                ("d").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");
            WriteTrashFile("c/c/c", "1\nc(main)\n3\n");
            git.Add().AddFilepattern("a").AddFilepattern("c/c/c").Call();
            RevCommit thirdCommit = git.Commit().SetMessage("main").Call();

            WriteTrashFile("d", "--- dirty ---");
            MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
                                                                                         .RESOLVE).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
            NUnit.Framework.Assert.AreEqual("1(side)\na\n3(main)\n", Read(new FilePath(db.WorkTree
                                                                                       , "a")));
            NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree,
                                                                                 "b")));
            NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree,
                                                                                 "c/c/c")));
            NUnit.Framework.Assert.AreEqual("--- dirty ---", Read(new FilePath(db.WorkTree, "d"
                                                                               )));
            NUnit.Framework.Assert.AreEqual(null, result.GetConflicts());
            NUnit.Framework.Assert.IsTrue(2 == result.GetMergedCommits().Length);
            NUnit.Framework.Assert.AreEqual(thirdCommit, result.GetMergedCommits()[0]);
            NUnit.Framework.Assert.AreEqual(secondCommit, result.GetMergedCommits()[1]);
            Iterator <RevCommit> it      = git.Log().Call().Iterator();
            RevCommit            newHead = it.Next();

            NUnit.Framework.Assert.AreEqual(newHead, result.GetNewHead());
            NUnit.Framework.Assert.AreEqual(2, newHead.ParentCount);
            NUnit.Framework.Assert.AreEqual(thirdCommit, newHead.GetParent(0));
            NUnit.Framework.Assert.AreEqual(secondCommit, newHead.GetParent(1));
            NUnit.Framework.Assert.AreEqual("Merge commit '064d54d98a4cdb0fed1802a21c656bfda67fe879'"
                                            , newHead.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState());
        }
Esempio n. 4
0
        public virtual void TestAlreadyUpToDate()
        {
            Git       git   = new Git(db);
            RevCommit first = git.Commit().SetMessage("initial commit").Call();

            CreateBranch(first, "refs/heads/branch1");
            RevCommit          second = git.Commit().SetMessage("second commit").Call();
            MergeCommandResult result = git.Merge().Include(db.GetRef("refs/heads/branch1")).
                                        Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.ALREADY_UP_TO_DATE, result.GetMergeStatus
                                                ());
            NUnit.Framework.Assert.AreEqual(second, result.GetNewHead());
        }
Esempio n. 5
0
        public virtual void TestFastForward()
        {
            Git       git   = new Git(db);
            RevCommit first = git.Commit().SetMessage("initial commit").Call();

            CreateBranch(first, "refs/heads/branch1");
            RevCommit second = git.Commit().SetMessage("second commit").Call();

            CheckoutBranch("refs/heads/branch1");
            MergeCommandResult result = git.Merge().Include(db.GetRef(Constants.MASTER)).Call
                                            ();

            NUnit.Framework.Assert.AreEqual(MergeStatus.FAST_FORWARD, result.GetMergeStatus()
                                            );
            NUnit.Framework.Assert.AreEqual(second, result.GetNewHead());
        }