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()); }
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()); }
public virtual void CheckMergeEqualTreesInCore(MergeStrategy strategy) { Git git = Git.Wrap(db); WriteTrashFile("d/1", "orig"); git.Add().AddFilepattern("d/1").Call(); RevCommit first = git.Commit().SetMessage("added d/1").Call(); WriteTrashFile("d/1", "modified"); RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on master" ).Call(); git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call(); WriteTrashFile("d/1", "modified"); RevCommit sideCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on side" ).Call(); git.Rm().AddFilepattern("d/1").Call(); git.Rm().AddFilepattern("d").Call(); ThreeWayMerger resolveMerger = (ThreeWayMerger)strategy.NewMerger(db, true); bool noProblems = resolveMerger.Merge(masterCommit, sideCommit); NUnit.Framework.Assert.IsTrue(noProblems); }