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


C# Commit.Save方法代码示例

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


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

示例1: 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, 1154236443L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443L, -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, 1154236443L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443L, -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, 1154236443L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443L, -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, 1154236443L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443L, -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:HackerBaloo,项目名称:GitSharp,代码行数:96,代码来源:WriteTests.cs

示例2: Write_Simple_Commit

        public void Write_Simple_Commit()
        {
            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");
            t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
            //new ObjectChecker().checkBlob(Constants.CHARSET.GetString(db.OpenObject(t.TreeId).getBytes()).ToCharArray());

            string s = new Inspector(db).Inspect(t.Id);
            string s1 = Inspector.Inspect("Resources/single_file_commit", "16c0beaf7523eb3ef5df45bd42dd4fc6343de864");
            string s2 = Inspector.Inspect("Resources/single_file_commit", "917c130bd4fa5bf2df0c399dc1b03401860aa448");
            string s3 = Inspector.Inspect("Resources/single_file_commit", "95ea6a6859af6791464bd8b6de76ad5a6f9fad81");

            //tree 917c130bd4fa5bf2df0c399dc1b03401860aa448\nauthor henon <[email protected]> 1245946742 +0200\ncommitter henon <[email protected]> 1245946742 +0200\n\nA Commit\n"

            Assert.AreEqual(ObjectId.FromString("917c130bd4fa5bf2df0c399dc1b03401860aa448"), t.Id);

            var c = new Commit(db)
                        {
                            Author = (new PersonIdent("henon", "[email protected]", 1245946742, 2*60)),
                            Committer = (new PersonIdent("henon", "[email protected]", 1245946742, 2*60)),
                            Message = ("A Commit\n"),
                            TreeEntry = (t)
                        };
            Assert.AreEqual(t.TreeId, c.TreeId);
            c.Save();

            string s_c = new Inspector(db).Inspect(c.CommitId);
            ObjectId cmtid = ObjectId.FromString("16c0beaf7523eb3ef5df45bd42dd4fc6343de864");
            Assert.AreEqual(cmtid, c.CommitId);

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

            // Verify we can Read it.
            Commit c2 = db.MapCommit(cmtid.ToString());
            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:HackerBaloo,项目名称:GitSharp,代码行数:47,代码来源:WriteTests.cs

示例3: test009_CreateCommitOldFormat

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

            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);

            var s = new Inspector(db).Inspect(t.Id);

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

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

            var sc = new Inspector(db).Inspect(c.CommitId);

            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.ToString());
            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:HackerBaloo,项目名称:GitSharp,代码行数:51,代码来源:WriteTests.cs


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