当前位置: 首页>>代码示例>>C#>>正文


C# Tree.AddFile方法代码示例

本文整理汇总了C#中GitSharp.Core.Tree.AddFile方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.AddFile方法的具体用法?C# Tree.AddFile怎么用?C# Tree.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GitSharp.Core.Tree的用法示例。


在下文中一共展示了Tree.AddFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: testSimpleF1

 public void testSimpleF1()
 {
     Tree tree = new Tree(db);
     tree.AddFile("x");
     TreeIterator i = MakeIterator(tree);
     Assert.IsTrue(i.hasNext());
     Assert.AreEqual("x", i.next().Name);
 }
开发者ID:georgeck,项目名称:GitSharp,代码行数:8,代码来源:TreeIteratorLeafOnlyTest.cs

示例2: test007_manyFileLookup

 public void test007_manyFileLookup()
 {
     var t = new Tree(db);
     var files = new List<FileTreeEntry>(26 * 26);
     for (char level1 = 'a'; level1 <= 'z'; level1++)
     {
         for (char level2 = 'a'; level2 <= 'z'; level2++)
         {
             String n = "." + level1 + level2 + "9";
             FileTreeEntry f = t.AddFile(n);
             Assert.IsNotNull(f, "File " + n + " added.");
             Assert.AreEqual(n, f.Name);
             files.Add(f);
         }
     }
     Assert.AreEqual(files.Count, t.MemberCount);
     TreeEntry[] ents = t.Members;
     Assert.IsNotNull(ents);
     Assert.AreEqual(files.Count, ents.Length);
     for (int k = 0; k < ents.Length; k++)
     {
         Assert.IsTrue(files[k] == ents[k], "File " + files[k].Name + " is at " + k + ".");
     }
 }
开发者ID:georgeck,项目名称:GitSharp,代码行数:24,代码来源:T0002_Tree.cs

示例3: test005_addRecursiveFile

 public void test005_addRecursiveFile()
 {
     var t = new Tree(db);
     FileTreeEntry f = t.AddFile("a/b/c");
     Assert.IsNotNull(f);
     Assert.AreEqual(f.Name, "c");
     Assert.AreEqual(f.Parent.Name, "b");
     Assert.AreEqual(f.Parent.Parent.Name, "a");
     Assert.IsTrue(t == f.Parent.Parent.Parent, "t is great-grandparent");
 }
开发者ID:georgeck,项目名称:GitSharp,代码行数:10,代码来源:T0002_Tree.cs

示例4: test002_addFile

        public void test002_addFile()
        {
            var t = new Tree(db) { Id = SomeFakeId };
            Assert.IsTrue(t.Id != null);
            Assert.IsFalse(t.IsModified);

            const string n = "bob";
            FileTreeEntry f = t.AddFile(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(t.IsModified);
            Assert.IsTrue(t.Id == null);
            Assert.IsTrue(t.FindBlobMember(f.Name) == f);

            TreeEntry[] i = t.Members;
            Assert.IsNotNull(i);
            Assert.IsTrue(i != null && i.Length > 0);
            Assert.IsTrue(i != null && i[0] == f);
            Assert.IsTrue(i != null && i.Length == 1);
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:23,代码来源:T0002_Tree.cs

示例5: BuildTree

 private Tree BuildTree(Dictionary<string, string> headEntries)
 {
     var tree = new Tree(db);
     if (headEntries != null)
     {
         foreach (var pair in headEntries)
         {
             tree.AddFile(pair.Key).Id = GenSha1(pair.Value);
         }
     }
     return tree;
 }
开发者ID:georgeck,项目名称:GitSharp,代码行数:12,代码来源:ReadTreeTest.cs

示例6: Write_Tree

        public void Write_Tree()
        {
            var t = new Tree(db);
            FileTreeEntry f = t.AddFile("i-am-a-file");
            writeTrashFile(f.Name, "and this is the data in me\r\n\r\n");
            Assert.AreEqual(File.ReadAllText("Resources/single_file_commit/i-am-a-file"), File.ReadAllText(trash + "/i-am-a-file"));
            t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
            var id = t.Id;

            var b1 = new BinaryReader(new Inspector(db).ContentStream(id));
            b1.BaseStream.Position = b1.BaseStream.Length - 21;

            var b2 = new BinaryReader(Inspector.ContentStream("Resources/single_file_commit", "917c130bd4fa5bf2df0c399dc1b03401860aa448"));
            b2.BaseStream.Position = b2.BaseStream.Length - 21;
            Assert.AreEqual(b2.ReadByte(), b1.ReadByte());

            var git_w1=b2.ReadInt32();
            var git_w2=b2.ReadInt32();
            var git_w3 = b2.ReadInt32();
            var git_w4 = b2.ReadInt32();
            var git_w5 = b2.ReadInt32();
            b2.BaseStream.Position = b2.BaseStream.Length-20;
            var git_id = ObjectId.FromRaw(b2.ReadBytes(20));
            var w1 = b1.ReadInt32();
            var w2= b1.ReadInt32();
            b1.Close();
            b2.Close();

            Assert.AreEqual(git_w1,w1);
            Assert.AreEqual(git_w2, w2);

            Assert.AreEqual("917c130bd4fa5bf2df0c399dc1b03401860aa448", id.ToString());
            var s_git = Inspector.Inspect("Resources/single_file_commit", "917c130bd4fa5bf2df0c399dc1b03401860aa448");
            var s = new Inspector(db).Inspect(id);
            Assert.AreEqual(s_git, s);
        }
开发者ID:mdekrey,项目名称:GitSharp,代码行数:36,代码来源:T0003_Basic_Write.cs

示例7: test026_CreateCommitMultipleparents

        public void test026_CreateCommitMultipleparents()
        {
            db.Config.load();

            var t = new Tree(db);
            FileTreeEntry f = t.AddFile("i-am-a-file");
            writeTrashFile(f.Name, "and this is the data in me\n");
            t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
            Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"),
                    t.TreeId);

            var c1 = new Commit(db)
                     	{
                     		Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443000L, -4*60),
                     		Message = "A Commit\n",
                     		TreeEntry = t
                     	};

            Assert.AreEqual(t.TreeId, c1.TreeId);
            c1.Save();
            ObjectId cmtid1 = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099");
            Assert.AreEqual(cmtid1, c1.CommitId);

            var c2 = new Commit(db)
                     	{
                     		Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443000L, -4*60),
                     		Message = "A Commit 2\n",
                     		TreeEntry = t
                     	};

            Assert.AreEqual(t.TreeId, c2.TreeId);
            c2.ParentIds = new[] { c1.CommitId };
            c2.Save();
            ObjectId cmtid2 = ObjectId.FromString("95d068687c91c5c044fb8c77c5154d5247901553");
            Assert.AreEqual(cmtid2, c2.CommitId);

            Commit rm2 = db.MapCommit(cmtid2);
            Assert.AreNotSame(c2, rm2); // assert the parsed objects is not from the cache
            Assert.AreEqual(c2.Author, rm2.Author);
            Assert.AreEqual(c2.CommitId, rm2.CommitId);
            Assert.AreEqual(c2.Message, rm2.Message);
            Assert.AreEqual(c2.TreeEntry.TreeId, rm2.TreeEntry.TreeId);
            Assert.AreEqual(1, rm2.ParentIds.Length);
            Assert.AreEqual(c1.CommitId, rm2.ParentIds[0]);

            var c3 = new Commit(db)
                     	{
                     		Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443000L, -4*60),
                     		Message = "A Commit 3\n",
                     		TreeEntry = t
                     	};

            Assert.AreEqual(t.TreeId, c3.TreeId);
            c3.ParentIds = new[] { c1.CommitId, c2.CommitId };
            c3.Save();
            ObjectId cmtid3 = ObjectId.FromString("ce6e1ce48fbeeb15a83f628dc8dc2debefa066f4");
            Assert.AreEqual(cmtid3, c3.CommitId);

            Commit rm3 = db.MapCommit(cmtid3);
            Assert.AreNotSame(c3, rm3); // assert the parsed objects is not from the cache
            Assert.AreEqual(c3.Author, rm3.Author);
            Assert.AreEqual(c3.CommitId, rm3.CommitId);
            Assert.AreEqual(c3.Message, rm3.Message);
            Assert.AreEqual(c3.TreeEntry.TreeId, rm3.TreeEntry.TreeId);
            Assert.AreEqual(2, rm3.ParentIds.Length);
            Assert.AreEqual(c1.CommitId, rm3.ParentIds[0]);
            Assert.AreEqual(c2.CommitId, rm3.ParentIds[1]);

            var c4 = new Commit(db)
                     	{
                     		Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443000L, -4*60),
                     		Message = "A Commit 4\n",
                     		TreeEntry = t
                     	};

            Assert.AreEqual(t.TreeId, c3.TreeId);
            c4.ParentIds = new[] { c1.CommitId, c2.CommitId, c3.CommitId };
            c4.Save();
            ObjectId cmtid4 = ObjectId.FromString("d1fca9fe3fef54e5212eb67902c8ed3e79736e27");
            Assert.AreEqual(cmtid4, c4.CommitId);

            Commit rm4 = db.MapCommit(cmtid4);
            Assert.AreNotSame(c4, rm3); // assert the parsed objects is not from the cache
            Assert.AreEqual(c4.Author, rm4.Author);
            Assert.AreEqual(c4.CommitId, rm4.CommitId);
            Assert.AreEqual(c4.Message, rm4.Message);
            Assert.AreEqual(c4.TreeEntry.TreeId, rm4.TreeEntry.TreeId);
            Assert.AreEqual(3, rm4.ParentIds.Length);
            Assert.AreEqual(c1.CommitId, rm4.ParentIds[0]);
            Assert.AreEqual(c2.CommitId, rm4.ParentIds[1]);
            Assert.AreEqual(c3.CommitId, rm4.ParentIds[2]);
        }
开发者ID:mdekrey,项目名称:GitSharp,代码行数:96,代码来源:T0003_Basic_Write.cs

示例8: test009_CreateCommitOldFormat

        public void test009_CreateCommitOldFormat()
        {
            writeTrashFile(".git/config", "[core]\n" + "legacyHeaders=1\n");
            db.Config.load();
            Assert.AreEqual(true, db.Config.getBoolean("core", "legacyHeaders", false));

            var t = new Tree(db);
            FileTreeEntry f = t.AddFile("i-am-a-file");
            writeTrashFile(f.Name, "and this is the data in me\n");
            t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);

            Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), t.TreeId);

            var c = new Commit(db)
                        {
                            Author = (new PersonIdent(jauthor, 1154236443000L, -4*60)),
                            Committer = (new PersonIdent(jcommitter, 1154236443000L, -4*60)),
                            Message = ("A Commit\n"),
                            TreeEntry = t
                        };
            Assert.AreEqual(t.TreeId, c.TreeId);
            c.Save();

            ObjectId cmtid = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099");
            Assert.AreEqual(cmtid, c.CommitId);

            // Verify the commit we just wrote is in the correct format.
            var xis = new XInputStream(new FileStream(db.ToFile(cmtid).FullName, System.IO.FileMode.Open, FileAccess.Read));
            try
            {
                Assert.AreEqual(0x78, xis.ReadUInt8());
                Assert.AreEqual(0x9c, xis.ReadUInt8());
                Assert.IsTrue(0x789c % 31 == 0);
            }
            finally
            {
                xis.Close();
            }

            // Verify we can Read it.
            Commit c2 = db.MapCommit(cmtid);
            Assert.IsNotNull(c2);
            Assert.AreEqual(c.Message, c2.Message);
            Assert.AreEqual(c.TreeId, c2.TreeId);
            Assert.AreEqual(c.Author, c2.Author);
            Assert.AreEqual(c.Committer, c2.Committer);
        }
开发者ID:mdekrey,项目名称:GitSharp,代码行数:47,代码来源:T0003_Basic_Write.cs

示例9: testUnchangedComplex

        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);
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:36,代码来源:IndexDiffTest.cs

示例10: testRemoved

        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);
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:25,代码来源:IndexDiffTest.cs

示例11: testTricky

        public void testTricky()
        {
            Tree tree = new Tree(db);
            tree.AddFile("a.b");
            tree.AddFile("a.c");
            tree.AddFile("a/b.b/b");
            tree.AddFile("a/b");
            tree.AddFile("a/c");
            tree.AddFile("a=c");
            tree.AddFile("a=d");

            TreeIterator i = MakeIterator(tree);
            Assert.IsTrue(i.hasNext());
            Assert.AreEqual("a.b", i.next().FullName);
            Assert.IsTrue(i.hasNext());
            Assert.AreEqual("a.c", i.next().FullName);
            Assert.IsTrue(i.hasNext());
            Assert.AreEqual("a/b", i.next().FullName);
            Assert.IsTrue(i.hasNext());
            Assert.AreEqual("a/b.b/b", i.next().FullName);
            Assert.IsTrue(i.hasNext());
            Assert.AreEqual("a/c", i.next().FullName);
            Assert.IsTrue(i.hasNext());
            Assert.AreEqual("a=c", i.next().FullName);
            Assert.IsTrue(i.hasNext());
            Assert.AreEqual("a=d", i.next().FullName);
            Assert.IsFalse(i.hasNext());
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:28,代码来源:TreeIteratorLeafOnlyTest.cs

示例12: testTreeOnlyOneLevel

        public void testTreeOnlyOneLevel()
        {
            var index = new GitIndex(db);
            var mainTree = new Tree(db);
            mainTree.AddFile("foo");
            mainTree.AddFile("bar");

            new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk();

            Assert.IsTrue(TreeOnlyEntriesVisited[0].Equals("bar"));
            Assert.IsTrue(TreeOnlyEntriesVisited[1].Equals("foo"));
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:12,代码来源:IndexTreeWalkerTest.cs

示例13: testBoth

        public void testBoth()
        {
            var index = new GitIndex(db);
            var mainTree = new Tree(db);

            index.add(trash, writeTrashFile("a", "a"));
            mainTree.AddFile("b/b");
            index.add(trash, writeTrashFile("c", "c"));
            mainTree.AddFile("c");

            new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk();
            Assert.IsTrue(IndexOnlyEntriesVisited.Contains("a"));
            Assert.IsTrue(TreeOnlyEntriesVisited.Contains("b/b"));
            Assert.IsTrue(BothVisited.Contains("c"));
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:15,代码来源:IndexTreeWalkerTest.cs

示例14: test008_SubtreeInternalSorting

        public void test008_SubtreeInternalSorting()
        {
            var t = new Tree(db);
            FileTreeEntry e0 = t.AddFile("a-b");
            FileTreeEntry e1 = t.AddFile("a-");
            FileTreeEntry e2 = t.AddFile("a=b");
            Tree e3 = t.AddTree("a");
            FileTreeEntry e4 = t.AddFile("a=");

            TreeEntry[] ents = t.Members;
            Assert.AreSame(e1, ents[0]);
            Assert.AreSame(e0, ents[1]);
            Assert.AreSame(e3, ents[2]);
            Assert.AreSame(e4, ents[3]);
            Assert.AreSame(e2, ents[4]);
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:16,代码来源:T0002_Tree.cs

示例15: testUnchangedSimple

        public void testUnchangedSimple()
        {
            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=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=c").Id = ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714");
            t.AddFile("a=d").Id = ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2");
            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);
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:25,代码来源:IndexDiffTest.cs


注:本文中的GitSharp.Core.Tree.AddFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。