Exemplo n.º 1
0
        public virtual void TestFindObjects()
        {
            DirCache        tree0 = DirCache.NewInCore();
            DirCacheBuilder b0    = tree0.Builder();
            ObjectReader    or    = db.NewObjectReader();
            ObjectInserter  oi    = db.NewObjectInserter();
            DirCacheEntry   aDotB = MakeEntry("a.b", EXECUTABLE_FILE);

            b0.Add(aDotB);
            DirCacheEntry aSlashB = MakeEntry("a/b", REGULAR_FILE);

            b0.Add(aSlashB);
            DirCacheEntry aSlashCSlashD = MakeEntry("a/c/d", REGULAR_FILE);

            b0.Add(aSlashCSlashD);
            DirCacheEntry aZeroB = MakeEntry("a0b", SYMLINK);

            b0.Add(aZeroB);
            b0.Finish();
            NUnit.Framework.Assert.AreEqual(4, tree0.GetEntryCount());
            ObjectId tree = tree0.WriteTree(oi);
            // Find the directories that were implicitly created above.
            TreeWalk tw = new TreeWalk(or);

            tw.AddTree(tree);
            ObjectId a       = null;
            ObjectId aSlashC = null;

            while (tw.Next())
            {
                if (tw.PathString.Equals("a"))
                {
                    a = tw.GetObjectId(0);
                    tw.EnterSubtree();
                    while (tw.Next())
                    {
                        if (tw.PathString.Equals("a/c"))
                        {
                            aSlashC = tw.GetObjectId(0);
                            break;
                        }
                    }
                    break;
                }
            }
            NUnit.Framework.Assert.AreEqual(a, TreeWalk.ForPath(or, "a", tree).GetObjectId(0)
                                            );
            NUnit.Framework.Assert.AreEqual(a, TreeWalk.ForPath(or, "a/", tree).GetObjectId(0
                                                                                            ));
            NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a", tree));
            NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a/", tree));
            NUnit.Framework.Assert.AreEqual(aDotB.GetObjectId(), TreeWalk.ForPath(or, "a.b",
                                                                                  tree).GetObjectId(0));
            NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a.b", tree));
            NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a.b/", tree));
            NUnit.Framework.Assert.AreEqual(aDotB.GetObjectId(), TreeWalk.ForPath(or, "a.b/",
                                                                                  tree).GetObjectId(0));
            NUnit.Framework.Assert.AreEqual(aZeroB.GetObjectId(), TreeWalk.ForPath(or, "a0b",
                                                                                   tree).GetObjectId(0));
            NUnit.Framework.Assert.AreEqual(aSlashB.GetObjectId(), TreeWalk.ForPath(or, "a/b"
                                                                                    , tree).GetObjectId(0));
            NUnit.Framework.Assert.AreEqual(aSlashB.GetObjectId(), TreeWalk.ForPath(or, "b",
                                                                                    a).GetObjectId(0));
            NUnit.Framework.Assert.AreEqual(aSlashC, TreeWalk.ForPath(or, "a/c", tree).GetObjectId
                                                (0));
            NUnit.Framework.Assert.AreEqual(aSlashC, TreeWalk.ForPath(or, "c", a).GetObjectId
                                                (0));
            NUnit.Framework.Assert.AreEqual(aSlashCSlashD.GetObjectId(), TreeWalk.ForPath(or,
                                                                                          "a/c/d", tree).GetObjectId(0));
            NUnit.Framework.Assert.AreEqual(aSlashCSlashD.GetObjectId(), TreeWalk.ForPath(or,
                                                                                          "c/d", a).GetObjectId(0));
            or.Release();
            oi.Release();
        }