findTreeMember() public method

public findTreeMember ( string treeName ) : TreeEntry
treeName string Tree name
return TreeEntry
Example #1
0
 /// <summary>
 /// Find a Blob or Tree by traversing the tree along the given path. You can access not only direct children
 /// of the tree but any descendant of this tree.
 /// <para/>
 /// The path's directory seperators may be both forward or backslash, it is converted automatically to the internal representation.
 /// <para/>
 /// Throws IOException.
 /// </summary>
 /// <param name="path">Relative path to a file or directory in the git tree. For directories a trailing slash is allowed</param>
 /// <returns>A tree or blob object representing the referenced object</returns>
 public AbstractObject this[string path]
 {
     get
     {
         if (path == "")
         {
             return(this);
         }
         var tree_entry = _internal_tree.FindBlobMember(path);
         if (tree_entry == null)
         {
             tree_entry = _internal_tree.findTreeMember(path);
         }
         if (tree_entry == null)
         {
             return(null);
         }
         if (tree_entry.IsTree)
         {
             return(new Tree(_repo, tree_entry as CoreTree));
         }
         else if (tree_entry.IsBlob)
         {
             return(new Leaf(_repo, tree_entry as FileTreeEntry));
         }
         else                 // if (tree_entry.IsCommit || tree_entry.IsTag)
         {
             return(AbstractObject.Wrap(_repo, tree_entry.Id));
         }
     }
 }
Example #2
0
        public void test006_addDeepTree()
        {
            var t = new Tree(db);

            Tree e = t.AddTree("e");
            Assert.IsNotNull(e);
            Assert.IsTrue(e.Parent == t);
            Tree f = t.AddTree("f");
            Assert.IsNotNull(f);
            Assert.IsTrue(f.Parent == t);
            Tree g = f.AddTree("g");
            Assert.IsNotNull(g);
            Assert.IsTrue(g.Parent == f);
            Tree h = g.AddTree("h");
            Assert.IsNotNull(h);
            Assert.IsTrue(h.Parent == g);

            h.Id = SomeFakeId;
            Assert.IsTrue(!h.IsModified);
            g.Id = SomeFakeId;
            Assert.IsTrue(!g.IsModified);
            f.Id = SomeFakeId;
            Assert.IsTrue(!f.IsModified);
            e.Id = SomeFakeId;
            Assert.IsTrue(!e.IsModified);
            t.Id = SomeFakeId;
            Assert.IsTrue(!t.IsModified);

            Assert.AreEqual("f/g/h", h.FullName);
            Assert.IsTrue(t.findTreeMember(h.FullName) == h);
            Assert.IsTrue(t.FindBlobMember("f/z") == null);
            Assert.IsTrue(t.FindBlobMember("y/z") == null);

            FileTreeEntry i = h.AddFile("i");
            Assert.IsNotNull(i);
            Assert.AreEqual("f/g/h/i", i.FullName);
            Assert.IsTrue(t.FindBlobMember(i.FullName) == i);
            Assert.IsTrue(h.IsModified);
            Assert.IsTrue(g.IsModified);
            Assert.IsTrue(f.IsModified);
            Assert.IsTrue(!e.IsModified);
            Assert.IsTrue(t.IsModified);

            Assert.IsTrue(h.Id == null);
            Assert.IsTrue(g.Id == null);
            Assert.IsTrue(f.Id == null);
            Assert.IsTrue(e.Id != null);
            Assert.IsTrue(t.Id == null);
        }
Example #3
0
        public void test004_addTree()
        {
            var t = new Tree(db) {Id = SomeFakeId};
            Assert.IsTrue(t.Id != null);
            Assert.IsFalse(t.IsModified);

            const string n = "bob";
            Tree f = t.AddTree(n);
            Assert.IsNotNull(f);
            Assert.AreEqual(n, f.Name);
            Assert.AreEqual(f.Name, Constants.CHARSET.GetString(f.NameUTF8));
            Assert.AreEqual(n, f.FullName);
            Assert.IsTrue(f.Id == null);
            Assert.IsTrue(f.Parent == t);
            Assert.IsTrue(f.Repository == db);
            Assert.IsTrue(f.IsLoaded);
            Assert.IsFalse(f.Members.Length > 0);
            Assert.IsFalse(f.IsRoot);
            Assert.IsTrue(f.TreeEntry == f);
            Assert.IsTrue(t.IsModified);
            Assert.IsTrue(t.Id == null);
            Assert.IsTrue(t.findTreeMember(f.Name) == f);

            TreeEntry[] i = t.Members;
            Assert.IsTrue(i.Length > 0);
            Assert.IsTrue(i[0] == f);
            Assert.IsTrue(i.Length == 1);
        }
Example #4
0
 public void test001_createEmpty()
 {
     var t = new Tree(db);
     Assert.IsTrue(t.IsLoaded);
     Assert.IsTrue(t.IsModified);
     Assert.IsTrue(t.Parent == null);
     Assert.IsTrue(t.IsRoot);
     Assert.IsTrue(t.Name == null);
     Assert.IsTrue(t.NameUTF8 == null);
     Assert.IsTrue(t.Members != null);
     Assert.IsTrue(t.Members.Length == 0);
     Assert.AreEqual(string.Empty, t.FullName);
     Assert.IsTrue(t.Id == null);
     Assert.IsTrue(t.TreeEntry == t);
     Assert.IsTrue(t.Repository == db);
     Assert.IsTrue(t.findTreeMember("foo") == null);
     Assert.IsTrue(t.FindBlobMember("foo") == null);
 }
Example #5
0
        public void testModified()
        {
            var index = new GitIndex(db);

            index.add(trash, writeTrashFile("file2", "file2"));
            index.add(trash, writeTrashFile("dir/file3", "dir/file3"));

            writeTrashFile("dir/file3", "changed");

            var t = new Tree(db);
            t.AddFile("file2").Id = ObjectId.FromString("0123456789012345678901234567890123456789");
            t.AddFile("dir/file3").Id = ObjectId.FromString("0123456789012345678901234567890123456789");
            Assert.AreEqual(2, t.MemberCount);

            var tree2 = (Tree) t.findTreeMember("dir");
            tree2.Id = new ObjectWriter(db).WriteTree(tree2);
            t.Id = new ObjectWriter(db).WriteTree(t);
            var diff = new IndexDiff(t, index);
            diff.Diff();
            Assert.AreEqual(2, diff.Changed.Count);
            Assert.IsTrue(diff.Changed.Contains("file2"));
            Assert.IsTrue(diff.Changed.Contains("dir/file3"));
            Assert.AreEqual(1, diff.Modified.Count);
            Assert.IsTrue(diff.Modified.Contains("dir/file3"));
            Assert.AreEqual(0, diff.Added.Count);
            Assert.AreEqual(0, diff.Removed.Count);
            Assert.AreEqual(0, diff.Missing.Count);
        }
Example #6
0
        public void testUnchangedComplex()
        {
            var index = new GitIndex(db);
            index.add(trash, writeTrashFile("a.b", "a.b"));
            index.add(trash, writeTrashFile("a.c", "a.c"));
            index.add(trash, writeTrashFile("a/b.b/b", "a/b.b/b"));
            index.add(trash, writeTrashFile("a/b", "a/b"));
            index.add(trash, writeTrashFile("a/c", "a/c"));
            index.add(trash, writeTrashFile("a=c", "a=c"));
            index.add(trash, writeTrashFile("a=d", "a=d"));

            var t = new Tree(db);
            t.AddFile("a.b").Id = ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851");
            t.AddFile("a.c").Id = ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca");
            t.AddFile("a/b.b/b").Id = ObjectId.FromString("8d840bd4e2f3a48ff417c8e927d94996849933fd");
            t.AddFile("a/b").Id = ObjectId.FromString("db89c972fc57862eae378f45b74aca228037d415");
            t.AddFile("a/c").Id = ObjectId.FromString("52ad142a008aeb39694bafff8e8f1be75ed7f007");
            t.AddFile("a=c").Id = ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714");
            t.AddFile("a=d").Id = ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2");

            var tree2 = (Tree) t.findTreeMember("a/b.b");
            tree2.Id = new ObjectWriter(db).WriteTree(tree2);

            var tree3 = (Tree) t.findTreeMember("a");
            tree3.Id = new ObjectWriter(db).WriteTree(tree3);
            t.Id = new ObjectWriter(db).WriteTree(t);

            var diff = new IndexDiff(t, index);
            diff.Diff();

            Assert.AreEqual(0, diff.Changed.Count);
            Assert.AreEqual(0, diff.Added.Count);
            Assert.AreEqual(0, diff.Removed.Count);
            Assert.AreEqual(0, diff.Missing.Count);
            Assert.AreEqual(0, diff.Modified.Count);
        }
Example #7
0
        public void testRemoved()
        {
            var index = new GitIndex(db);
            writeTrashFile("file2", "file2");
            writeTrashFile("dir/file3", "dir/file3");

            var t = new Tree(db);
            t.AddFile("file2");
            t.AddFile("dir/file3");
            Assert.AreEqual(2, t.MemberCount);
            t.FindBlobMember("file2").Id = ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad");
            var tree2 = (Tree) t.findTreeMember("dir");
            tree2.FindBlobMember("file3").Id = ObjectId.FromString("873fb8d667d05436d728c52b1d7a09528e6eb59b");
            tree2.Id = new ObjectWriter(db).WriteTree(tree2);
            t.Id = new ObjectWriter(db).WriteTree(t);

            var diff = new IndexDiff(t, index);
            diff.Diff();
            Assert.AreEqual(2, diff.Removed.Count);
            Assert.IsTrue(diff.Removed.Contains("file2"));
            Assert.IsTrue(diff.Removed.Contains("dir/file3"));
            Assert.AreEqual(0, diff.Changed.Count);
            Assert.AreEqual(0, diff.Modified.Count);
            Assert.AreEqual(0, diff.Added.Count);
        }