Пример #1
0
        public void testSingleSubtree()
        {
            DirCache dc = DirCache.read(db);

            string[]        paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
            }
            int aFirst = 1;
            int aLast  = 3;

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }
            b.finish();

            Assert.IsNull(dc.getCacheTree(false));
            DirCacheTree root = dc.getCacheTree(true);

            Assert.IsNotNull(root);
            Assert.AreSame(root, dc.getCacheTree(true));
            Assert.AreEqual(string.Empty, root.getNameString());
            Assert.AreEqual(string.Empty, root.getPathString());
            Assert.AreEqual(1, root.getChildCount());
            Assert.AreEqual(dc.getEntryCount(), root.getEntrySpan());
            Assert.IsFalse(root.isValid());

            DirCacheTree aTree = root.getChild(0);

            Assert.IsNotNull(aTree);
            Assert.AreSame(aTree, root.getChild(0));
            Assert.AreEqual("a", aTree.getNameString());
            Assert.AreEqual("a/", aTree.getPathString());
            Assert.AreEqual(0, aTree.getChildCount());
            Assert.AreEqual(aLast - aFirst + 1, aTree.getEntrySpan());
            Assert.IsFalse(aTree.isValid());
        }
Пример #2
0
        public void testTwoLevelSubtree_FilterPath()
        {
            DirCache dc = DirCache.read(db);

            FileMode mode = FileMode.RegularFile;

            string[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
            var      ents  = new DirCacheEntry[paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(mode);
            }

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }
            b.finish();

            var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);

            for (int victimIdx = 0; victimIdx < paths.Length; victimIdx++)
            {
                tw.reset();
                tw.addTree(new DirCacheIterator(dc));
                tw.setFilter(PathFilterGroup.createFromStrings(new[] { paths[victimIdx] }));
                tw.Recursive = tw.getFilter().shouldBeRecursive();
                Assert.IsTrue(tw.next());
                var c = tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator));
                Assert.IsNotNull(c);
                Assert.AreEqual(victimIdx, c.Pointer);
                Assert.AreSame(ents[victimIdx], c.getDirCacheEntry());
                Assert.AreEqual(paths[victimIdx], tw.getPathString());
                Assert.AreEqual(mode.Bits, tw.getRawMode(0));
                Assert.AreSame(mode, tw.getFileMode(0));
                Assert.IsFalse(tw.next());
            }
        }
Пример #3
0
        public void testNoSubtree_WithTreeWalk()
        {
            DirCache dc = DirCache.read(db);

            string[]   paths = { "a.", "a0b" };
            FileMode[] modes = { FileMode.ExecutableFile, FileMode.GitLink };
            var        ents  = new DirCacheEntry[paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(modes[i]);
            }

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }
            b.finish();

            var iter = new DirCacheIterator(dc);
            var tw   = new TreeWalk(db);

            tw.reset();
            tw.addTree(iter);
            int pathIdx = 0;

            while (tw.next())
            {
                Assert.AreSame(iter, tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator)));
                Assert.AreEqual(pathIdx, iter.Pointer);
                Assert.AreSame(ents[pathIdx], iter.getDirCacheEntry());
                Assert.AreEqual(paths[pathIdx], tw.getPathString());
                Assert.AreEqual(modes[pathIdx].Bits, tw.getRawMode(0));
                Assert.AreSame(modes[pathIdx], tw.getFileMode(0));
                pathIdx++;
            }
            Assert.AreEqual(paths.Length, pathIdx);
        }
Пример #4
0
            private void Add(int tree, int stage)
            {
                AbstractTreeIterator i = GetTree(tree);

                if (i == null)
                {
                    return;
                }

                if (FileMode.Tree.Equals(_tw.getRawMode(tree)))
                {
                    _builder.addTree(_tw.getRawPath(), stage, Repository, _tw.getObjectId(tree));
                }
                else
                {
                    var e = new DirCacheEntry(_tw.getRawPath(), stage);
                    e.setObjectIdFromRaw(i.idBuffer(), i.idOffset());
                    e.setFileMode(_tw.getFileMode(tree));
                    _builder.add(e);
                }
            }
Пример #5
0
        public 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 = DirCache.read(db);
            DirCache treeO = DirCache.read(db);
            DirCache treeP = DirCache.read(db);
            DirCache treeT = DirCache.read(db);
            {
                DirCacheBuilder b = treeB.builder();
                DirCacheBuilder o = treeO.builder();
                DirCacheBuilder p = treeP.builder();
                DirCacheBuilder t = treeT.builder();

                b.add(MakeEntry("a", FileMode.RegularFile));

                o.add(MakeEntry("a", FileMode.RegularFile));
                o.add(MakeEntry("o", FileMode.RegularFile));

                p.add(MakeEntry("a", FileMode.RegularFile, "q"));
                p.add(MakeEntry("p-fail", FileMode.RegularFile));

                t.add(MakeEntry("a", FileMode.RegularFile));
                t.add(MakeEntry("t", FileMode.RegularFile));

                b.finish();
                o.finish();
                p.finish();
                t.finish();
            }

            var      ow = new ObjectWriter(db);
            ObjectId B  = Commit(ow, treeB, new ObjectId[] { });
            ObjectId O  = Commit(ow, treeO, new[] { B });
            ObjectId P  = Commit(ow, treeP, new[] { B });
            ObjectId T  = Commit(ow, treeT, new[] { P });

            var twm = (ThreeWayMerger)MergeStrategy.SimpleTwoWayInCore.NewMerger(db);

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

            Assert.IsTrue(merge);

            var tw = new GitSharp.Core.TreeWalk.TreeWalk(db)
            {
                Recursive = true
            };

            tw.reset(twm.GetResultTreeId());

            Assert.IsTrue(tw.next());
            Assert.AreEqual("a", tw.getPathString());
            AssertCorrectId(treeO, tw);

            Assert.IsTrue(tw.next());
            Assert.AreEqual("o", tw.getPathString());
            AssertCorrectId(treeO, tw);

            Assert.IsTrue(tw.next());
            Assert.AreEqual("t", tw.getPathString());
            AssertCorrectId(treeT, tw);

            Assert.IsFalse(tw.next());
        }