コード例 #1
0
        public virtual void TestPick()
        {
            // B---O
            // \----P---T
            //
            // Cherry-pick "T" onto "O". This shouldn't introduce "p-fail", which
            // was created by "P", nor should it modify "a", which was done by "P".
            //
            DirCache treeB = db.ReadDirCache();
            DirCache treeO = db.ReadDirCache();
            DirCache treeP = db.ReadDirCache();
            DirCache treeT = db.ReadDirCache();
            {
                DirCacheBuilder b = treeB.Builder();
                DirCacheBuilder o = treeO.Builder();
                DirCacheBuilder p = treeP.Builder();
                DirCacheBuilder t = treeT.Builder();
                b.Add(MakeEntry("a", FileMode.REGULAR_FILE));
                o.Add(MakeEntry("a", FileMode.REGULAR_FILE));
                o.Add(MakeEntry("o", FileMode.REGULAR_FILE));
                p.Add(MakeEntry("a", FileMode.REGULAR_FILE, "q"));
                p.Add(MakeEntry("p-fail", FileMode.REGULAR_FILE));
                t.Add(MakeEntry("a", FileMode.REGULAR_FILE));
                t.Add(MakeEntry("t", FileMode.REGULAR_FILE));
                b.Finish();
                o.Finish();
                p.Finish();
                t.Finish();
            }
            ObjectInserter ow  = db.NewObjectInserter();
            ObjectId       B   = Commit(ow, treeB, new ObjectId[] {  });
            ObjectId       O   = Commit(ow, treeO, new ObjectId[] { B });
            ObjectId       P   = Commit(ow, treeP, new ObjectId[] { B });
            ObjectId       T   = Commit(ow, treeT, new ObjectId[] { P });
            ThreeWayMerger twm = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
                                      (db));

            twm.SetBase(P);
            bool merge = twm.Merge(new ObjectId[] { O, T });

            NUnit.Framework.Assert.IsTrue(merge);
            TreeWalk tw = new TreeWalk(db);

            tw.Recursive = true;
            tw.Reset(twm.GetResultTreeId());
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("a", tw.PathString);
            AssertCorrectId(treeO, tw);
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("o", tw.PathString);
            AssertCorrectId(treeO, tw);
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("t", tw.PathString);
            AssertCorrectId(treeT, tw);
            NUnit.Framework.Assert.IsFalse(tw.Next());
        }
コード例 #2
0
        public virtual void TestRevert()
        {
            // B---P---T
            //
            // Revert P, this should result in a tree with a
            // from B and t from T as the change to a in P
            // and addition of t in P is reverted.
            //
            // We use the standard merge, but change the order
            // of the sources.
            //
            DirCache treeB = db.ReadDirCache();
            DirCache treeP = db.ReadDirCache();
            DirCache treeT = db.ReadDirCache();
            {
                DirCacheBuilder b = treeB.Builder();
                DirCacheBuilder p = treeP.Builder();
                DirCacheBuilder t = treeT.Builder();
                b.Add(MakeEntry("a", FileMode.REGULAR_FILE));
                p.Add(MakeEntry("a", FileMode.REGULAR_FILE, "q"));
                p.Add(MakeEntry("p-fail", FileMode.REGULAR_FILE));
                t.Add(MakeEntry("a", FileMode.REGULAR_FILE, "q"));
                t.Add(MakeEntry("p-fail", FileMode.REGULAR_FILE));
                t.Add(MakeEntry("t", FileMode.REGULAR_FILE));
                b.Finish();
                p.Finish();
                t.Finish();
            }
            ObjectInserter ow  = db.NewObjectInserter();
            ObjectId       B   = Commit(ow, treeB, new ObjectId[] {  });
            ObjectId       P   = Commit(ow, treeP, new ObjectId[] { B });
            ObjectId       T   = Commit(ow, treeT, new ObjectId[] { P });
            ThreeWayMerger twm = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
                                      (db));

            twm.SetBase(P);
            bool merge = twm.Merge(new ObjectId[] { B, T });

            NUnit.Framework.Assert.IsTrue(merge);
            TreeWalk tw = new TreeWalk(db);

            tw.Recursive = true;
            tw.Reset(twm.GetResultTreeId());
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("a", tw.PathString);
            AssertCorrectId(treeB, tw);
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("t", tw.PathString);
            AssertCorrectId(treeT, tw);
            NUnit.Framework.Assert.IsFalse(tw.Next());
        }