Example #1
0
        public virtual void Test005_addRecursiveTree()
        {
            Tree t = new Tree(db);
            Tree f = t.AddTree("a/b/c");

            NUnit.Framework.Assert.IsNotNull(f, "created f");
            NUnit.Framework.Assert.AreEqual("c", f.GetName());
            NUnit.Framework.Assert.AreEqual("b", f.GetParent().GetName());
            NUnit.Framework.Assert.AreEqual("a", f.GetParent().GetParent().GetName());
            NUnit.Framework.Assert.IsTrue(t == f.GetParent().GetParent().GetParent(), "t is great-grandparent"
                                          );
        }
Example #2
0
        public virtual void Test004_addTree()
        {
            Tree t = new Tree(db);

            t.SetId(SOME_FAKE_ID);
            NUnit.Framework.Assert.IsTrue(t.GetId() != null, "has id");
            NUnit.Framework.Assert.IsFalse(t.IsModified(), "not modified");
            string n = "bob";
            Tree   f = t.AddTree(n);

            NUnit.Framework.Assert.IsNotNull(f, "have tree");
            NUnit.Framework.Assert.AreEqual(n, f.GetName(), "name matches");
            NUnit.Framework.Assert.AreEqual(f.GetName(), Sharpen.Runtime.GetStringForBytes(f.
                                                                                           GetNameUTF8(), "UTF-8"), "name matches");
            NUnit.Framework.Assert.AreEqual(n, f.GetFullName(), "full name matches");
            NUnit.Framework.Assert.IsTrue(f.GetId() == null, "no id");
            NUnit.Framework.Assert.IsTrue(f.GetParent() == t, "parent matches");
            NUnit.Framework.Assert.IsTrue(f.GetRepository() == db, "repository matches");
            NUnit.Framework.Assert.IsTrue(f.IsLoaded(), "isLoaded");
            NUnit.Framework.Assert.IsFalse(f.Members().Length > 0, "has items");
            NUnit.Framework.Assert.IsFalse(f.IsRoot(), "is root");
            NUnit.Framework.Assert.IsTrue(t.IsModified(), "parent is modified");
            NUnit.Framework.Assert.IsTrue(t.GetId() == null, "parent has no id");
            NUnit.Framework.Assert.IsTrue(t.FindTreeMember(f.GetName()) == f, "found bob child"
                                          );
            TreeEntry[] i = t.Members();
            NUnit.Framework.Assert.IsTrue(i.Length > 0, "iterator is not empty");
            NUnit.Framework.Assert.IsTrue(i[0] == f, "iterator returns file");
            NUnit.Framework.Assert.AreEqual(1, i.Length, "iterator is empty");
        }
Example #3
0
        public virtual void Test006_addDeepTree()
        {
            Tree t = new Tree(db);
            Tree e = t.AddTree("e");

            NUnit.Framework.Assert.IsNotNull(e, "have e");
            NUnit.Framework.Assert.IsTrue(e.GetParent() == t, "e.parent == t");
            Tree f = t.AddTree("f");

            NUnit.Framework.Assert.IsNotNull(f, "have f");
            NUnit.Framework.Assert.IsTrue(f.GetParent() == t, "f.parent == t");
            Tree g = f.AddTree("g");

            NUnit.Framework.Assert.IsNotNull(g, "have g");
            NUnit.Framework.Assert.IsTrue(g.GetParent() == f, "g.parent == f");
            Tree h = g.AddTree("h");

            NUnit.Framework.Assert.IsNotNull(h, "have h");
            NUnit.Framework.Assert.IsTrue(h.GetParent() == g, "h.parent = g");
            h.SetId(SOME_FAKE_ID);
            NUnit.Framework.Assert.IsTrue(!h.IsModified(), "h not modified");
            g.SetId(SOME_FAKE_ID);
            NUnit.Framework.Assert.IsTrue(!g.IsModified(), "g not modified");
            f.SetId(SOME_FAKE_ID);
            NUnit.Framework.Assert.IsTrue(!f.IsModified(), "f not modified");
            e.SetId(SOME_FAKE_ID);
            NUnit.Framework.Assert.IsTrue(!e.IsModified(), "e not modified");
            t.SetId(SOME_FAKE_ID);
            NUnit.Framework.Assert.IsTrue(!t.IsModified(), "t not modified.");
            NUnit.Framework.Assert.AreEqual("f/g/h", h.GetFullName(), "full path of h ok");
            NUnit.Framework.Assert.IsTrue(t.FindTreeMember(h.GetFullName()) == h, "Can find h"
                                          );
            NUnit.Framework.Assert.IsTrue(t.FindBlobMember("f/z") == null, "Can't find f/z");
            NUnit.Framework.Assert.IsTrue(t.FindBlobMember("y/z") == null, "Can't find y/z");
            FileTreeEntry i = h.AddFile("i");

            NUnit.Framework.Assert.IsNotNull(i);
            NUnit.Framework.Assert.AreEqual("f/g/h/i", i.GetFullName(), "full path of i ok");
            NUnit.Framework.Assert.IsTrue(t.FindBlobMember(i.GetFullName()) == i, "Can find i"
                                          );
            NUnit.Framework.Assert.IsTrue(h.IsModified(), "h modified");
            NUnit.Framework.Assert.IsTrue(g.IsModified(), "g modified");
            NUnit.Framework.Assert.IsTrue(f.IsModified(), "f modified");
            NUnit.Framework.Assert.IsTrue(!e.IsModified(), "e not modified");
            NUnit.Framework.Assert.IsTrue(t.IsModified(), "t modified");
            NUnit.Framework.Assert.IsTrue(h.GetId() == null, "h no id");
            NUnit.Framework.Assert.IsTrue(g.GetId() == null, "g no id");
            NUnit.Framework.Assert.IsTrue(f.GetId() == null, "f no id");
            NUnit.Framework.Assert.IsTrue(e.GetId() != null, "e has id");
            NUnit.Framework.Assert.IsTrue(t.GetId() == null, "t no id");
        }
Example #4
0
        public virtual void Test001_createEmpty()
        {
            Tree t = new Tree(db);

            NUnit.Framework.Assert.IsTrue(t.IsLoaded(), "isLoaded");
            NUnit.Framework.Assert.IsTrue(t.IsModified(), "isModified");
            NUnit.Framework.Assert.IsTrue(t.GetParent() == null, "no parent");
            NUnit.Framework.Assert.IsTrue(t.IsRoot(), "isRoot");
            NUnit.Framework.Assert.IsTrue(t.GetName() == null, "no name");
            NUnit.Framework.Assert.IsTrue(t.GetNameUTF8() == null, "no nameUTF8");
            NUnit.Framework.Assert.IsTrue(t.Members() != null, "has entries array");
            NUnit.Framework.Assert.AreEqual(0, t.Members().Length, "entries is empty");
            NUnit.Framework.Assert.AreEqual(string.Empty, t.GetFullName(), "full name is empty"
                                            );
            NUnit.Framework.Assert.IsTrue(t.GetId() == null, "no id");
            NUnit.Framework.Assert.IsTrue(t.GetRepository() == db, "database is r");
            NUnit.Framework.Assert.IsTrue(t.FindTreeMember("foo") == null, "no foo child");
            NUnit.Framework.Assert.IsTrue(t.FindBlobMember("foo") == null, "no foo child");
        }
        /// <summary>Construct and write tree out of index.</summary>
        /// <remarks>Construct and write tree out of index.</remarks>
        /// <returns>SHA-1 of the constructed tree</returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual ObjectId WriteTree()
        {
            CheckWriteOk();
            ObjectInserter inserter = db.NewObjectInserter();

            try
            {
                Tree         current = new Tree(db);
                Stack <Tree> trees   = new Stack <Tree>();
                trees.Push(current);
                string[] prevName = new string[0];
                foreach (GitIndex.Entry e in entries.Values)
                {
                    if (e.GetStage() != 0)
                    {
                        continue;
                    }
                    string[] newName = SplitDirPath(e.GetName());
                    int      c       = LongestCommonPath(prevName, newName);
                    while (c < trees.Count - 1)
                    {
                        current.SetId(inserter.Insert(Constants.OBJ_TREE, current.Format()));
                        trees.Pop();
                        current = trees.IsEmpty() ? null : (Tree)trees.Peek();
                    }
                    while (trees.Count < newName.Length)
                    {
                        if (!current.ExistsTree(newName[trees.Count - 1]))
                        {
                            current = new Tree(current, Constants.Encode(newName[trees.Count - 1]));
                            current.GetParent().AddEntry(current);
                            trees.Push(current);
                        }
                        else
                        {
                            current = (Tree)current.FindTreeMember(newName[trees.Count - 1]);
                            trees.Push(current);
                        }
                    }
                    FileTreeEntry ne = new FileTreeEntry(current, e.sha1, Constants.Encode(newName[newName
                                                                                                   .Length - 1]), (e.mode & FileMode.EXECUTABLE_FILE.GetBits()) == FileMode.EXECUTABLE_FILE
                                                         .GetBits());
                    current.AddEntry(ne);
                }
                while (!trees.IsEmpty())
                {
                    current.SetId(inserter.Insert(Constants.OBJ_TREE, current.Format()));
                    trees.Pop();
                    if (!trees.IsEmpty())
                    {
                        current = trees.Peek();
                    }
                }
                inserter.Flush();
                return(current.GetId());
            }
            finally
            {
                inserter.Release();
            }
        }
Example #6
0
		public virtual void Test001_createEmpty()
		{
			Tree t = new Tree(db);
			NUnit.Framework.Assert.IsTrue(t.IsLoaded(), "isLoaded");
			NUnit.Framework.Assert.IsTrue(t.IsModified(), "isModified");
			NUnit.Framework.Assert.IsTrue(t.GetParent() == null, "no parent");
			NUnit.Framework.Assert.IsTrue(t.IsRoot(), "isRoot");
			NUnit.Framework.Assert.IsTrue(t.GetName() == null, "no name");
			NUnit.Framework.Assert.IsTrue(t.GetNameUTF8() == null, "no nameUTF8");
			NUnit.Framework.Assert.IsTrue(t.Members() != null, "has entries array");
			NUnit.Framework.Assert.AreEqual(0, t.Members().Length, "entries is empty");
			NUnit.Framework.Assert.AreEqual(string.Empty, t.GetFullName(), "full name is empty"
				);
			NUnit.Framework.Assert.IsTrue(t.GetId() == null, "no id");
			NUnit.Framework.Assert.IsTrue(t.GetRepository() == db, "database is r");
			NUnit.Framework.Assert.IsTrue(t.FindTreeMember("foo") == null, "no foo child");
			NUnit.Framework.Assert.IsTrue(t.FindBlobMember("foo") == null, "no foo child");
		}