Exemple #1
0
        public virtual void Test002_addFile()
        {
            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";
            FileTreeEntry f = t.AddFile(n);

            NUnit.Framework.Assert.IsNotNull(f, "have file");
            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(t.IsModified(), "is modified");
            NUnit.Framework.Assert.IsTrue(t.GetId() == null, "has no id");
            NUnit.Framework.Assert.IsTrue(t.FindBlobMember(f.GetName()) == f, "found bob");
            TreeEntry[] i = t.Members();
            NUnit.Framework.Assert.IsNotNull(i, "members array not null");
            NUnit.Framework.Assert.IsTrue(i != null && i.Length > 0, "iterator is not empty");
            NUnit.Framework.Assert.IsTrue(i != null && i[0] == f, "iterator returns file");
            NUnit.Framework.Assert.IsTrue(i != null && i.Length == 1, "iterator is empty");
        }
Exemple #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");
        }
Exemple #3
0
        public virtual void TestUnchangedSimple()
        {
            GitIndex 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=c", "a=c"));
            index.Add(trash, WriteTrashFile("a=d", "a=d"));
            index.Write();
            Tree tree = new Tree(db);

            // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
            tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
                                                          ));
            tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
                                                          ));
            tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
                                                          ));
            tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
                                                          ));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
        }
Exemple #4
0
        public virtual void TestModified()
        {
            GitIndex index = new GitIndex(db);

            index.Add(trash, WriteTrashFile("file2", "file2"));
            index.Add(trash, WriteTrashFile("dir/file3", "dir/file3"));
            index.Write();
            WriteTrashFile("dir/file3", "changed");
            Tree tree = new Tree(db);

            tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
                                                            ));
            tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
                                                                ));
            NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
            Tree tree2 = (Tree)tree.FindTreeMember("dir");

            tree2.SetId(InsertTree(tree2));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
            NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
        }
        public virtual void TestModified()
        {
            WriteTrashFile("file2", "file2");
            WriteTrashFile("dir/file3", "dir/file3");
            Git git = new Git(db);

            git.Add().AddFilepattern("file2").AddFilepattern("dir/file3").Call();
            WriteTrashFile("dir/file3", "changed");
            Tree tree = new Tree(db);

            tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
                                                            ));
            tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
                                                                ));
            NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
            Tree tree2 = (Tree)tree.FindTreeMember("dir");

            tree2.SetId(InsertTree(tree2));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
            NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders()
                                            );
        }
        public virtual void TestAdded()
        {
            WriteTrashFile("file1", "file1");
            WriteTrashFile("dir/subfile", "dir/subfile");
            Tree tree = new Tree(db);

            tree.SetId(InsertTree(tree));
            DirCache       index  = db.LockDirCache();
            DirCacheEditor editor = index.Editor();

            editor.Add(Add(db, trash, "file1"));
            editor.Add(Add(db, trash, "dir/subfile"));
            editor.Commit();
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
            NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.CollectionAssert.AreEquivalent(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders()
                                                           );
        }
Exemple #7
0
        public virtual void TestRemoved()
        {
            WriteTrashFile("file2", "file2");
            WriteTrashFile("dir/file3", "dir/file3");
            Tree tree = new Tree(db);

            tree.AddFile("file2");
            tree.AddFile("dir/file3");
            NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
            tree.FindBlobMember("file2").SetId(ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad"
                                                                   ));
            Tree tree2 = (Tree)tree.FindTreeMember("dir");

            tree2.FindBlobMember("file3").SetId(ObjectId.FromString("873fb8d667d05436d728c52b1d7a09528e6eb59b"
                                                                    ));
            tree2.SetId(InsertTree(tree2));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetRemoved().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("file2"));
            NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
        }
Exemple #8
0
		/// <exception cref="System.InvalidOperationException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public override void PrescanTwoTrees(Tree head, Tree merge)
		{
			DirCache dc = db.LockDirCache();
			try
			{
				dco = new DirCacheCheckout(db, head.GetId(), dc, merge.GetId());
				dco.PreScanTwoTrees();
			}
			finally
			{
				dc.Unlock();
			}
		}
Exemple #9
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");
        }
Exemple #10
0
        /// <exception cref="System.InvalidOperationException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public override void PrescanTwoTrees(Tree head, Tree merge)
        {
            DirCache dc = db.LockDirCache();

            try
            {
                dco = new DirCacheCheckout(db, head.GetId(), dc, merge.GetId());
                dco.PreScanTwoTrees();
            }
            finally
            {
                dc.Unlock();
            }
        }
        public virtual void TestUnchangedComplex()
        {
            Git git = new Git(db);

            WriteTrashFile("a.b", "a.b");
            WriteTrashFile("a.c", "a.c");
            WriteTrashFile("a/b.b/b", "a/b.b/b");
            WriteTrashFile("a/b", "a/b");
            WriteTrashFile("a/c", "a/c");
            WriteTrashFile("a=c", "a=c");
            WriteTrashFile("a=d", "a=d");
            git.Add().AddFilepattern("a.b").AddFilepattern("a.c").AddFilepattern("a/b.b/b").AddFilepattern
                ("a/b").AddFilepattern("a/c").AddFilepattern("a=c").AddFilepattern("a=d").Call();
            Tree tree = new Tree(db);

            // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
            tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
                                                          ));
            tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
                                                          ));
            tree.AddFile("a/b.b/b").SetId(ObjectId.FromString("8d840bd4e2f3a48ff417c8e927d94996849933fd"
                                                              ));
            tree.AddFile("a/b").SetId(ObjectId.FromString("db89c972fc57862eae378f45b74aca228037d415"
                                                          ));
            tree.AddFile("a/c").SetId(ObjectId.FromString("52ad142a008aeb39694bafff8e8f1be75ed7f007"
                                                          ));
            tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
                                                          ));
            tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
                                                          ));
            Tree tree3 = (Tree)tree.FindTreeMember("a/b.b");

            tree3.SetId(InsertTree(tree3));
            Tree tree2 = (Tree)tree.FindTreeMember("a");

            tree2.SetId(InsertTree(tree2));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders()
                                            );
        }
Exemple #12
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");
        }
Exemple #13
0
 public virtual void TestAdded()
 {
     GitIndex index = new GitIndex(db);
     WriteTrashFile("file1", "file1");
     WriteTrashFile("dir/subfile", "dir/subfile");
     Tree tree = new Tree(db);
     tree.SetId(InsertTree(tree));
     index.Add(trash, new FilePath(trash, "file1"));
     index.Add(trash, new FilePath(trash, "dir/subfile"));
     index.Write();
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
 }
Exemple #14
0
 public virtual void TestAdded()
 {
     WriteTrashFile("file1", "file1");
     WriteTrashFile("dir/subfile", "dir/subfile");
     Tree tree = new Tree(db);
     tree.SetId(InsertTree(tree));
     DirCache index = db.LockDirCache();
     DirCacheEditor editor = index.Editor();
     editor.Add(Add(db, trash, "file1"));
     editor.Add(Add(db, trash, "dir/subfile"));
     editor.Commit();
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
Exemple #15
0
        public virtual void TestAdded()
        {
            GitIndex index = new GitIndex(db);

            WriteTrashFile("file1", "file1");
            WriteTrashFile("dir/subfile", "dir/subfile");
            Tree tree = new Tree(db);

            tree.SetId(InsertTree(tree));
            index.Add(trash, new FilePath(trash, "file1"));
            index.Add(trash, new FilePath(trash, "dir/subfile"));
            index.Write();
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
            NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
        }
Exemple #16
0
 public virtual void TestUnchangedComplex()
 {
     Git git = new Git(db);
     WriteTrashFile("a.b", "a.b");
     WriteTrashFile("a.c", "a.c");
     WriteTrashFile("a/b.b/b", "a/b.b/b");
     WriteTrashFile("a/b", "a/b");
     WriteTrashFile("a/c", "a/c");
     WriteTrashFile("a=c", "a=c");
     WriteTrashFile("a=d", "a=d");
     git.Add().AddFilepattern("a.b").AddFilepattern("a.c").AddFilepattern("a/b.b/b").AddFilepattern
         ("a/b").AddFilepattern("a/c").AddFilepattern("a=c").AddFilepattern("a=d").Call();
     Tree tree = new Tree(db);
     // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
     tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
         ));
     tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
         ));
     tree.AddFile("a/b.b/b").SetId(ObjectId.FromString("8d840bd4e2f3a48ff417c8e927d94996849933fd"
         ));
     tree.AddFile("a/b").SetId(ObjectId.FromString("db89c972fc57862eae378f45b74aca228037d415"
         ));
     tree.AddFile("a/c").SetId(ObjectId.FromString("52ad142a008aeb39694bafff8e8f1be75ed7f007"
         ));
     tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
         ));
     tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
         ));
     Tree tree3 = (Tree)tree.FindTreeMember("a/b.b");
     tree3.SetId(InsertTree(tree3));
     Tree tree2 = (Tree)tree.FindTreeMember("a");
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
Exemple #17
0
 public virtual void TestModified()
 {
     GitIndex index = new GitIndex(db);
     index.Add(trash, WriteTrashFile("file2", "file2"));
     index.Add(trash, WriteTrashFile("dir/file3", "dir/file3"));
     index.Write();
     WriteTrashFile("dir/file3", "changed");
     Tree tree = new Tree(db);
     tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
     Tree tree2 = (Tree)tree.FindTreeMember("dir");
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
 }
Exemple #18
0
		public virtual void TestEmptyTreeCorruption()
		{
			ObjectId bId = ObjectId.FromString("abbbfafe3129f85747aba7bfac992af77134c607");
			RevTree tree_root;
			RevTree tree_A;
			RevTree tree_AB;
			RevCommit b;
			{
				Tree root = new Tree(db);
				Tree A = root.AddTree("A");
				FileTreeEntry B = root.AddFile("B");
				B.SetId(bId);
				Tree A_A = A.AddTree("A");
				Tree A_B = A.AddTree("B");
				ObjectInserter inserter = db.NewObjectInserter();
				try
				{
					A_A.SetId(inserter.Insert(Constants.OBJ_TREE, A_A.Format()));
					A_B.SetId(inserter.Insert(Constants.OBJ_TREE, A_B.Format()));
					A.SetId(inserter.Insert(Constants.OBJ_TREE, A.Format()));
					root.SetId(inserter.Insert(Constants.OBJ_TREE, root.Format()));
					inserter.Flush();
				}
				finally
				{
					inserter.Release();
				}
				tree_root = rw.ParseTree(root.GetId());
				tree_A = rw.ParseTree(A.GetId());
				tree_AB = rw.ParseTree(A_A.GetId());
				NUnit.Framework.Assert.AreSame(tree_AB, rw.ParseTree(A_B.GetId()));
				b = Commit(rw.ParseTree(root.GetId()));
			}
			MarkStart(b);
			AssertCommit(b, objw.Next());
			NUnit.Framework.Assert.IsNull(objw.Next());
			NUnit.Framework.Assert.AreSame(tree_root, objw.NextObject());
			NUnit.Framework.Assert.AreSame(tree_A, objw.NextObject());
			NUnit.Framework.Assert.AreSame(tree_AB, objw.NextObject());
			NUnit.Framework.Assert.AreSame(rw.LookupBlob(bId), objw.NextObject());
			NUnit.Framework.Assert.IsNull(objw.NextObject());
		}
Exemple #19
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");
		}
Exemple #20
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");
		}
Exemple #21
0
		public virtual void Test002_addFile()
		{
			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";
			FileTreeEntry f = t.AddFile(n);
			NUnit.Framework.Assert.IsNotNull(f, "have file");
			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(t.IsModified(), "is modified");
			NUnit.Framework.Assert.IsTrue(t.GetId() == null, "has no id");
			NUnit.Framework.Assert.IsTrue(t.FindBlobMember(f.GetName()) == f, "found bob");
			TreeEntry[] i = t.Members();
			NUnit.Framework.Assert.IsNotNull(i, "members array not null");
			NUnit.Framework.Assert.IsTrue(i != null && i.Length > 0, "iterator is not empty");
			NUnit.Framework.Assert.IsTrue(i != null && i[0] == f, "iterator returns file");
			NUnit.Framework.Assert.IsTrue(i != null && i.Length == 1, "iterator is empty");
		}
Exemple #22
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");
		}
Exemple #23
0
 public virtual void TestUnchangedSimple()
 {
     WriteTrashFile("a.b", "a.b");
     WriteTrashFile("a.c", "a.c");
     WriteTrashFile("a=c", "a=c");
     WriteTrashFile("a=d", "a=d");
     Git git = new Git(db);
     git.Add().AddFilepattern("a.b").Call();
     git.Add().AddFilepattern("a.c").Call();
     git.Add().AddFilepattern("a=c").Call();
     git.Add().AddFilepattern("a=d").Call();
     Tree tree = new Tree(db);
     // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
     tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
         ));
     tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
         ));
     tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
         ));
     tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
         ));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
Exemple #24
0
 public virtual void TestRemoved()
 {
     WriteTrashFile("file2", "file2");
     WriteTrashFile("dir/file3", "dir/file3");
     Tree tree = new Tree(db);
     tree.AddFile("file2");
     tree.AddFile("dir/file3");
     NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
     tree.FindBlobMember("file2").SetId(ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad"
         ));
     Tree tree2 = (Tree)tree.FindTreeMember("dir");
     tree2.FindBlobMember("file3").SetId(ObjectId.FromString("873fb8d667d05436d728c52b1d7a09528e6eb59b"
         ));
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetRemoved().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
Exemple #25
0
 public virtual void TestModified()
 {
     WriteTrashFile("file2", "file2");
     WriteTrashFile("dir/file3", "dir/file3");
     Git git = new Git(db);
     git.Add().AddFilepattern("file2").AddFilepattern("dir/file3").Call();
     WriteTrashFile("dir/file3", "changed");
     Tree tree = new Tree(db);
     tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
     Tree tree2 = (Tree)tree.FindTreeMember("dir");
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }