示例#1
0
        public void testBuilderClear()
        {
            DirCache dc = DirCache.read(db);

            string[]        paths = { "a.", "a.b", "a/b", "a0b" };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(FileMode.RegularFile);
            }
            {
                DirCacheBuilder b = dc.builder();
                for (int i = 0; i < ents.Length; i++)
                {
                    b.add(ents[i]);
                }
                b.finish();
            }
            Assert.AreEqual(paths.Length, dc.getEntryCount());
            {
                DirCacheBuilder b = dc.builder();
                b.finish();
            }
            Assert.AreEqual(0, dc.getEntryCount());
        }
示例#2
0
        public void testFindSingleFile()
        {
            string          path = "a-File-path";
            DirCache        dc   = DirCache.read(db);
            DirCacheBuilder b    = dc.builder();

            Assert.IsNotNull(b);

            DirCacheEntry entOrig = new DirCacheEntry(path);

            entOrig.setFileMode(FileMode.RegularFile);
            Assert.AreNotSame(path, entOrig.getPathString());
            Assert.AreEqual(path, entOrig.getPathString());
            b.add(entOrig);
            b.finish();

            Assert.AreEqual(1, dc.getEntryCount());
            Assert.AreSame(entOrig, dc.getEntry(0));
            Assert.AreEqual(0, dc.findEntry(path));

            Assert.AreEqual(-1, dc.findEntry("@@-before"));
            Assert.AreEqual(0, real(dc.findEntry("@@-before")));

            Assert.AreEqual(-2, dc.findEntry("a-zoo"));
            Assert.AreEqual(1, real(dc.findEntry("a-zoo")));

            Assert.AreSame(entOrig, dc.getEntry(path));
        }
示例#3
0
        public void testAdd_ReverseGitSortOrder()
        {
            DirCache dc = DirCache.read(db);

            string[]        paths = { "a.", "a.b", "a/b", "a0b" };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(FileMode.RegularFile);
            }

            DirCacheBuilder b = dc.builder();

            for (int i = ents.Length - 1; i >= 0; i--)
            {
                b.add(ents[i]);
            }
            b.finish();

            Assert.AreEqual(paths.Length, dc.getEntryCount());
            for (int i = 0; i < paths.Length; i++)
            {
                Assert.AreSame(ents[i], dc.getEntry(i));
                Assert.AreEqual(paths[i], dc.getEntry(i).getPathString());
                Assert.AreEqual(i, dc.findEntry(paths[i]));
                Assert.AreSame(ents[i], dc.getEntry(paths[i]));
            }
        }
        public virtual void testDF_NoGap()
        {
            DirCache tree0 = DirCache.read(db);
            DirCache tree1 = DirCache.read(db);
            {
                DirCacheBuilder b0 = tree0.builder();
                DirCacheBuilder b1 = tree1.builder();

                b0.add(makeEntry("a", REGULAR_FILE));
                b0.add(makeEntry("a.b", EXECUTABLE_FILE));
                b1.add(makeEntry("a/b", REGULAR_FILE));
                b0.add(makeEntry("a0b", SYMLINK));

                b0.finish();
                b1.finish();
                Assert.AreEqual(3, tree0.getEntryCount());
                Assert.AreEqual(1, tree1.getEntryCount());
            }

            NameConflictTreeWalk tw = new NameConflictTreeWalk(db);

            tw.reset();
            tw.addTree(new DirCacheIterator(tree0));
            tw.addTree(new DirCacheIterator(tree1));

            assertModes("a", REGULAR_FILE, TREE, tw);
            Assert.IsTrue(tw.isSubtree());
            tw.enterSubtree();
            assertModes("a/b", MISSING, REGULAR_FILE, tw);
            assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
            assertModes("a0b", SYMLINK, MISSING, tw);
        }
示例#5
0
        public void testNoSubtree_NoTreeWalk()
        {
            DirCache dc = DirCache.read(db);

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

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

            DirCacheBuilder b = dc.builder();

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

            b.finish();

            var iter    = new DirCacheIterator(dc);
            int pathIdx = 0;

            for (; !iter.eof(); iter.next(1))
            {
                Assert.AreEqual(pathIdx, iter.Pointer);
                Assert.AreSame(ents[pathIdx], iter.getDirCacheEntry());
                pathIdx++;
            }

            Assert.AreEqual(paths.Length, pathIdx);
        }
示例#6
0
        public void testTrivialTwoWay_rightDFconflict2()
        {
            DirCache treeB = DirCache.read(db);
            DirCache treeO = DirCache.read(db);
            DirCache treeT = DirCache.read(db);
            {
                DirCacheBuilder b = treeB.builder();
                DirCacheBuilder o = treeO.builder();
                DirCacheBuilder t = treeT.builder();

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

                o.add(MakeEntry("d/o", FileMode.RegularFile));

                t.add(MakeEntry("d", FileMode.RegularFile, "t !"));

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

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

            Merger ourMerger = MergeStrategy.SimpleTwoWayInCore.NewMerger(db);
            bool   merge     = ourMerger.Merge(new[] { O, T });

            Assert.IsFalse(merge);
        }
示例#7
0
        public void testBuildThenClear()
        {
            DirCache dc = DirCache.read(db);

            string[] paths = { "a.", "a.b", "a/b", "a0b" };

            var ents = new DirCacheEntry[paths.Length];

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

            DirCacheBuilder b = dc.builder();

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

            b.finish();

            Assert.AreEqual(paths.Length, dc.getEntryCount());
            dc.clear();
            Assert.AreEqual(0, dc.getEntryCount());
        }
示例#8
0
        public void testNoPostOrder()
        {
            DirCache tree = DirCache.read(db);
            {
                DirCacheBuilder b = tree.builder();

                b.add(makeFile("a"));
                b.add(makeFile("b/c"));
                b.add(makeFile("b/d"));
                b.add(makeFile("q"));

                b.finish();
                Assert.AreEqual(4, tree.getEntryCount());
            }

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

            tw.reset();
            tw.PostOrderTraversal = false;
            tw.addTree(new DirCacheIterator(tree));

            assertModes("a", FileMode.RegularFile, tw);
            assertModes("b", FileMode.Tree, tw);
            Assert.IsTrue(tw.isSubtree());
            Assert.IsFalse(tw.isPostChildren());
            tw.enterSubtree();
            assertModes("b/c", FileMode.RegularFile, tw);
            assertModes("b/d", FileMode.RegularFile, tw);
            assertModes("q", FileMode.RegularFile, tw);
        }
示例#9
0
        public void testTrivialTwoWay_validSubtreeSort()
        {
            DirCache treeB = DirCache.read(db);
            DirCache treeO = DirCache.read(db);
            DirCache treeT = DirCache.read(db);
            {
                DirCacheBuilder b = treeB.builder();
                DirCacheBuilder o = treeO.builder();
                DirCacheBuilder t = treeT.builder();

                b.add(MakeEntry("libelf-po/a", FileMode.RegularFile));
                b.add(MakeEntry("libelf/c", FileMode.RegularFile));

                o.add(MakeEntry("Makefile", FileMode.RegularFile));
                o.add(MakeEntry("libelf-po/a", FileMode.RegularFile));
                o.add(MakeEntry("libelf/c", FileMode.RegularFile));

                t.add(MakeEntry("libelf-po/a", FileMode.RegularFile));
                t.add(MakeEntry("libelf/c", FileMode.RegularFile, "blah"));

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

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

            Merger ourMerger = MergeStrategy.SimpleTwoWayInCore.NewMerger(db);
            bool   merge     = ourMerger.Merge(new[] { O, T });

            Assert.IsTrue(merge);

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

            tw.reset(ourMerger.GetResultTreeId());

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

            Assert.IsTrue(tw.next());
            Assert.AreEqual("libelf-po/a", tw.getPathString());
            AssertCorrectId(treeO, tw);

            Assert.IsTrue(tw.next());
            Assert.AreEqual("libelf/c", tw.getPathString());
            AssertCorrectId(treeT, tw);

            Assert.IsFalse(tw.next());
        }
示例#10
0
        public void testTwoLevelSubtree()
        {
            DirCache dc = DirCache.read(db);

            string[]        paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(FileMode.RegularFile);
            }
            int aFirst  = 1;
            int aLast   = 4;
            int acFirst = 2;
            int acLast  = 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(1, aTree.getChildCount());
            Assert.AreEqual(aLast - aFirst + 1, aTree.getEntrySpan());
            Assert.IsFalse(aTree.isValid());

            DirCacheTree acTree = aTree.getChild(0);

            Assert.IsNotNull(acTree);
            Assert.AreSame(acTree, aTree.getChild(0));
            Assert.AreEqual("c", acTree.getNameString());
            Assert.AreEqual("a/c/", acTree.getPathString());
            Assert.AreEqual(0, acTree.getChildCount());
            Assert.AreEqual(acLast - acFirst + 1, acTree.getEntrySpan());
            Assert.IsFalse(acTree.isValid());
        }
示例#11
0
        public void testEntriesWithin()
        {
            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]);
                ents[i].setFileMode(FileMode.RegularFile);
            }

            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.AreEqual(paths.Length, dc.getEntryCount());
            for (int i = 0; i < ents.Length; i++)
            {
                Assert.AreSame(ents[i], dc.getEntry(i));
            }

            DirCacheEntry[] aContents = dc.getEntriesWithin("a");
            Assert.IsNotNull(aContents);
            Assert.AreEqual(aLast - aFirst + 1, aContents.Length);
            for (int i = aFirst, j = 0; i <= aLast; i++, j++)
            {
                Assert.AreSame(ents[i], aContents[j]);
            }

            aContents = dc.getEntriesWithin("a/");
            Assert.IsNotNull(aContents);
            Assert.AreEqual(aLast - aFirst + 1, aContents.Length);
            for (int i = aFirst, j = 0; i <= aLast; i++, j++)
            {
                Assert.AreSame(ents[i], aContents[j]);
            }

            Assert.IsNotNull(dc.getEntriesWithin("a."));
            Assert.AreEqual(0, dc.getEntriesWithin("a.").Length);

            Assert.IsNotNull(dc.getEntriesWithin("a0b"));
            Assert.AreEqual(0, dc.getEntriesWithin("a0b.").Length);

            Assert.IsNotNull(dc.getEntriesWithin("zoo"));
            Assert.AreEqual(0, dc.getEntriesWithin("zoo.").Length);
        }
示例#12
0
        public void testSingleSubtree_NoRecursion()
        {
            DirCache dc = DirCache.read(db);

            string[] paths = { "a.", "a/b", "a/c", "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(FileMode.RegularFile);
            }

            DirCacheBuilder b = dc.builder();

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

            string[]   expPaths = { "a.", "a", "a0b" };
            FileMode[] expModes = { FileMode.RegularFile, FileMode.Tree, FileMode.RegularFile };
            var        expPos   = new[] { 0, -1, 4 };

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

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

            while (tw.next())
            {
                Assert.AreSame(iter, tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator)));
                Assert.AreEqual(expModes[pathIdx].Bits, tw.getRawMode(0));
                Assert.AreSame(expModes[pathIdx], tw.getFileMode(0));
                Assert.AreEqual(expPaths[pathIdx], tw.getPathString());

                if (expPos[pathIdx] >= 0)
                {
                    Assert.AreEqual(expPos[pathIdx], iter.Pointer);
                    Assert.AreSame(ents[expPos[pathIdx]], iter.getDirCacheEntry());
                }
                else
                {
                    Assert.AreSame(FileMode.Tree, tw.getFileMode(0));
                }

                pathIdx++;
            }
            Assert.AreEqual(expPaths.Length, pathIdx);
        }
示例#13
0
 public CommitBuilder parent(RevCommit p)
 {
     if (parents.isEmpty())
     {
         DirCacheBuilder b = tree.builder();
         _testRepository.parseBody(p);
         b.addTree(new byte[0], DirCacheEntry.STAGE_0, _testRepository.db, p.Tree);
         b.finish();
     }
     parents.Add(p);
     return(this);
 }
示例#14
0
        public void testRecursiveFiltering()
        {
            var             ow        = new ObjectWriter(db);
            ObjectId        aSth      = ow.WriteBlob("a.sth".getBytes());
            ObjectId        aTxt      = ow.WriteBlob("a.txt".getBytes());
            ObjectId        bSth      = ow.WriteBlob("b.sth".getBytes());
            ObjectId        bTxt      = ow.WriteBlob("b.txt".getBytes());
            DirCache        dc        = DirCache.read(db);
            DirCacheBuilder builder   = dc.builder();
            var             aSthEntry = new DirCacheEntry("a.sth");

            aSthEntry.setFileMode(FileMode.RegularFile);
            aSthEntry.setObjectId(aSth);
            var aTxtEntry = new DirCacheEntry("a.txt");

            aTxtEntry.setFileMode(FileMode.RegularFile);
            aTxtEntry.setObjectId(aTxt);
            builder.add(aSthEntry);
            builder.add(aTxtEntry);
            var bSthEntry = new DirCacheEntry("sub/b.sth");

            bSthEntry.setFileMode(FileMode.RegularFile);
            bSthEntry.setObjectId(bSth);
            var bTxtEntry = new DirCacheEntry("sub/b.txt");

            bTxtEntry.setFileMode(FileMode.RegularFile);
            bTxtEntry.setObjectId(bTxt);
            builder.add(bSthEntry);
            builder.add(bTxtEntry);
            builder.finish();
            ObjectId treeId = dc.writeTree(ow);


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

            tw.Recursive = true;
            tw.setFilter(PathSuffixFilter.create(".txt"));
            tw.addTree(treeId);

            var paths = new LinkedList <string>();

            while (tw.next())
            {
                paths.AddLast(tw.getPathString());
            }

            var expected = new LinkedList <string>();

            expected.AddLast("a.txt");
            expected.AddLast("sub/b.txt");

            Assert.AreEqual(expected, paths);
        }
示例#15
0
        protected RevTree tree(params DirCacheEntry[] entries)
        {
            DirCache        dc = DirCache.newInCore();
            DirCacheBuilder b  = dc.builder();

            foreach (DirCacheEntry e in entries)
            {
                b.add(e);
            }
            b.finish();
            return(rw.lookupTree(dc.writeTree(_ow)));
        }
示例#16
0
        /**
         * Construct a tree from a specific listing of file entries.
         *
         * @param entries
         *            the files to include in the tree. The collection does not need
         *            to be sorted properly and may be empty.
         * @return reference to the tree specified by the entry list.
         * @throws Exception
         */
        public RevTree tree(params DirCacheEntry[] entries)
        {
            DirCache        dc = DirCache.newInCore();
            DirCacheBuilder b  = dc.builder();

            foreach (DirCacheEntry e in entries)
            {
                b.add(e);
            }
            b.finish();
            return(pool.lookupTree(dc.writeTree(writer)));
        }
示例#17
0
        public void testPathFilterGroup_DoesNotSkipTail()
        {
            DirCache dc = DirCache.read(db);

            var mode = FileMode.RegularFile;

            string[] paths = { "a.", "a/b", "a/c", "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 builder = dc.builder();

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

            const int       expIdx = 2;
            DirCacheBuilder b      = dc.builder();
            var             tw     = new GitSharp.Core.TreeWalk.TreeWalk(db);

            tw.reset();
            tw.addTree(new DirCacheBuildIterator(b));
            tw.Recursive = true;
            tw.setFilter(PathFilterGroup.createFromStrings(new[] { paths[expIdx] }));

            Assert.IsTrue(tw.next(), "found " + paths[expIdx]);
            var c = tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator));

            Assert.IsNotNull(c);
            Assert.AreEqual(expIdx, c.Pointer);
            Assert.AreSame(ents[expIdx], c.getDirCacheEntry());
            Assert.AreEqual(paths[expIdx], tw.getPathString());
            Assert.AreEqual(mode.Bits, tw.getRawMode(0));
            Assert.AreSame(mode, tw.getFileMode(0));
            b.add(c.getDirCacheEntry());

            Assert.IsFalse(tw.next(), "no more entries");

            b.finish();
            Assert.AreEqual(ents.Length, dc.getEntryCount());
            for (int i = 0; i < ents.Length; i++)
            {
                Assert.AreSame(ents[i], dc.getEntry(i));
            }
        }
示例#18
0
        public void testBuildEmpty()
        {
            DirCache        dc = DirCache.Lock(db);
            DirCacheBuilder b  = dc.builder();

            Assert.IsNotNull(b);
            b.finish();
            dc.write();
            Assert.IsTrue(dc.commit());

            dc = DirCache.read(db);
            Assert.AreEqual(0, dc.getEntryCount());
        }
示例#19
0
        public void testBuildOneFile_FinishWriteCommit()
        {
            string        path         = "a-File-path";
            var           mode         = FileMode.RegularFile;
            long          lastModified = 1218123387057L;
            int           Length       = 1342;
            DirCacheEntry entOrig;

            DirCache        dc = DirCache.Lock(db);
            DirCacheBuilder b  = dc.builder();

            Assert.IsNotNull(b);

            entOrig = new DirCacheEntry(path);
            entOrig.setFileMode(mode);
            entOrig.setLastModified(lastModified);
            entOrig.setLength(Length);

            Assert.AreNotSame(path, entOrig.getPathString());
            Assert.AreEqual(path, entOrig.getPathString());
            Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId());
            Assert.AreEqual(mode.Bits, entOrig.getRawMode());
            Assert.AreEqual(0, entOrig.getStage());
            Assert.AreEqual(lastModified, entOrig.getLastModified());
            Assert.AreEqual(Length, entOrig.getLength());
            Assert.IsFalse(entOrig.isAssumeValid());
            b.add(entOrig);

            b.finish();
            Assert.AreEqual(1, dc.getEntryCount());
            Assert.AreSame(entOrig, dc.getEntry(0));

            dc.write();
            Assert.IsTrue(dc.commit());

            dc = DirCache.read(db);
            Assert.AreEqual(1, dc.getEntryCount());

            DirCacheEntry entRead = dc.getEntry(0);

            Assert.AreNotSame(entOrig, entRead);
            Assert.AreEqual(path, entRead.getPathString());
            Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId());
            Assert.AreEqual(mode.Bits, entOrig.getRawMode());
            Assert.AreEqual(0, entOrig.getStage());
            Assert.AreEqual(lastModified, entOrig.getLastModified());
            Assert.AreEqual(Length, entOrig.getLength());
            Assert.IsFalse(entOrig.isAssumeValid());
        }
示例#20
0
            CommitBuilder(TestRepository testRepository, CommitBuilder prior)
            {
                _testRepository = testRepository;
                branch          = prior.branch;

                DirCacheBuilder b = tree.builder();

                for (int i = 0; i < prior.tree.getEntryCount(); i++)
                {
                    b.add(prior.tree.getEntry(i));
                }
                b.finish();

                parents.Add(prior.create());
            }
示例#21
0
        public void testSingleSubtree_Recursive()
        {
            DirCache dc = DirCache.read(db);

            FileMode mode = FileMode.RegularFile;

            string[] paths = { "a.", "a/b", "a/c", "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 iter = new DirCacheIterator(dc);
            var tw   = new TreeWalk(db);

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

            while (tw.next())
            {
                var c = tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator));
                Assert.IsNotNull(c);
                Assert.AreEqual(pathIdx, c.Pointer);
                Assert.AreSame(ents[pathIdx], c.getDirCacheEntry());
                Assert.AreEqual(paths[pathIdx], tw.getPathString());
                Assert.AreEqual(mode.Bits, tw.getRawMode(0));
                Assert.AreSame(mode, tw.getFileMode(0));
                pathIdx++;
            }

            Assert.AreEqual(paths.Length, pathIdx);
        }
示例#22
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 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());
            }
        }
示例#23
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);
        }
            protected override bool MergeImpl()
            {
                _tw.reset();
                _tw.addTree(MergeBase());
                _tw.addTree(SourceTrees[0]);
                _tw.addTree(SourceTrees[1]);

                bool hasConflict = false;

                _builder = _cache.builder();
                while (_tw.next())
                {
                    int modeO = _tw.getRawMode(Ours);
                    int modeT = _tw.getRawMode(Theirs);
                    if (modeO == modeT && _tw.idEqual(Ours, Theirs))
                    {
                        Add(Ours, DirCacheEntry.STAGE_0);
                        continue;
                    }

                    int modeB = _tw.getRawMode(Base);
                    if (modeB == modeO && _tw.idEqual(Base, Ours))
                    {
                        Add(Theirs, DirCacheEntry.STAGE_0);
                    }
                    else if (modeB == modeT && _tw.idEqual(Base, Theirs))
                    {
                        Add(Ours, DirCacheEntry.STAGE_0);
                    }
                    else if (_tw.isSubtree())
                    {
                        if (NonTree(modeB))
                        {
                            Add(Base, DirCacheEntry.STAGE_1);
                            hasConflict = true;
                        }
                        if (NonTree(modeO))
                        {
                            Add(Ours, DirCacheEntry.STAGE_2);
                            hasConflict = true;
                        }
                        if (NonTree(modeT))
                        {
                            Add(Theirs, DirCacheEntry.STAGE_3);
                            hasConflict = true;
                        }
                        _tw.enterSubtree();
                    }
                    else
                    {
                        Add(Base, DirCacheEntry.STAGE_1);
                        Add(Ours, DirCacheEntry.STAGE_2);
                        Add(Theirs, DirCacheEntry.STAGE_3);
                        hasConflict = true;
                    }
                }
                _builder.finish();
                _builder = null;

                if (hasConflict)
                {
                    return(false);
                }
                try
                {
                    _resultTree = _cache.writeTree(GetObjectWriter());
                    return(true);
                }
                catch (UnmergedPathException)
                {
                    _resultTree = null;
                    return(false);
                }
            }
示例#25
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());
        }