public static Commit Create(string message, IEnumerable <Commit> parents, Tree tree, Author author, Author committer, DateTimeOffset time) { if (string.IsNullOrEmpty(message)) { throw new ArgumentException("message must not be null or empty"); } if (tree == null) { throw new ArgumentException("tree must not be null"); } var repo = tree.Repository; var corecommit = new Core.Commit(repo._internal_repo); if (parents != null) { corecommit.ParentIds = parents.Select(parent => parent._id).ToArray(); } corecommit.Author = new Core.PersonIdent(author.Name, author.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes); corecommit.Committer = new Core.PersonIdent(committer.Name, committer.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes); corecommit.Message = message; corecommit.TreeEntry = tree.InternalTree; corecommit.Encoding = GetCommitEncoding(repo); corecommit.Save(); return(new Commit(repo, corecommit)); }
public void Commit(string message) { if (!this.HasGitRepository) return; if (string.IsNullOrEmpty(message)) throw new ArgumentException("Commit message must not be null or empty!", "message"); this.index.RereadIfNecessary(); var tree_id = this.index.writeTree(); var parent = repository.MapCommit(repository.Resolve("HEAD")); if ((parent == null && this.index.Members.Count == 0) || (parent != null && parent.TreeId == tree_id)) throw new InvalidOperationException("There are no changes to commit"); var corecommit = new Commit(this.repository); corecommit.ParentIds = parent == null ? new ObjectId[0] : new ObjectId[] { parent.TreeId }; var time = DateTimeOffset.Now; corecommit.Author = corecommit.Committer = new PersonIdent(this["user.name"], this["user.email"], time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes); corecommit.Message = message; corecommit.TreeEntry = this.repository.MapTree(tree_id); corecommit.Encoding = Charset.forName(this["i18n.commitencoding"] ?? "utf-8"); corecommit.Save(); var updateRef = this.repository.UpdateRef("HEAD"); updateRef.NewObjectId = corecommit.CommitId; updateRef.IsForceUpdate = true; updateRef.update(); Refresh(); }
public static Commit Create(string message, IEnumerable<Commit> parents, Tree tree, Author author, Author committer, DateTimeOffset time) { if (string.IsNullOrEmpty(message)) throw new ArgumentException("message must not be null or empty"); if (tree == null) throw new ArgumentException("tree must not be null"); var repo = tree.Repository; var corecommit = new Core.Commit(repo._internal_repo); if (parents != null) corecommit.ParentIds = parents.Select(parent => parent._id).ToArray(); corecommit.Author = new Core.PersonIdent(author.Name, author.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes); corecommit.Committer = new Core.PersonIdent(committer.Name, committer.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes); corecommit.Message = message; corecommit.TreeEntry = tree.InternalTree; corecommit.Encoding = GetCommitEncoding(repo); corecommit.Save(); return new Commit(repo, corecommit); }
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 <*****@*****.**> 1245946742 +0200\ncommitter henon <*****@*****.**> 1245946742 +0200\n\nA Commit\n" Assert.AreEqual(ObjectId.FromString("917c130bd4fa5bf2df0c399dc1b03401860aa448"), t.Id); var c = new Commit(db) { Author = (new PersonIdent("henon", "*****@*****.**", 1245946742000L, 2*60)), Committer = (new PersonIdent("henon", "*****@*****.**", 1245946742000L, 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); }
public void testTwoSuccessiveCommitsLinkedToHead() { var repo = createNewEmptyRepo(); var workingDirectory = repo.WorkingDirectory; repo.Create(); var objectWriter = new ObjectWriter(repo); FileInfo project1_a_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/A.txt"), "A.txt - first version\n"); FileInfo project1_b_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - first version\n"); var tree = new Tree(repo); Tree projectTree = tree.AddTree("Project-1"); addFile(projectTree, project1_a_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); addFile(projectTree, project1_b_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); tree.Id = (objectWriter.WriteTree(tree)); var commit = new Commit(repo) { Author = new PersonIdent(jauthor, (0L), 60), Committer = new PersonIdent(jcommitter, (0L), 60), Message = "Foo\n\nMessage", TreeEntry = tree }; commit.Save(); var commitId = commit.CommitId; FileInfo project1_b_v2_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - second version\n"); tree = new Tree(repo); projectTree = tree.AddTree("Project-1"); addFile(projectTree, project1_a_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); addFile(projectTree, project1_b_v2_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); tree.Id = (objectWriter.WriteTree(tree)); commit = new Commit(repo) { Author = new PersonIdent(jauthor, (0L), 60), Committer = new PersonIdent(jcommitter, (0L), 60), Message = "Modified", ParentIds = new[] { commitId }, TreeEntry = tree }; commit.Save(); commitId = commit.CommitId; RefUpdate lck = repo.UpdateRef("refs/heads/master"); Assert.IsNotNull(lck, "obtained lock"); lck.NewObjectId = commitId; Assert.AreEqual(RefUpdate.RefUpdateResult.New, lck.ForceUpdate()); }
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]); }
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); }
public static Commit Create(string message, Commit parent, Tree tree, Author author, Author committer, DateTimeOffset time) { if (string.IsNullOrEmpty(message)) throw new ArgumentException("message must not be null or empty"); if (tree == null) throw new ArgumentException("tree must not be null"); var repo = tree.Repository; var corecommit = new CoreCommit(repo._internal_repo); if (parent != null) corecommit.ParentIds = new GitSharp.Core.ObjectId[] { parent._id }; corecommit.Author = new GitSharp.Core.PersonIdent(author.Name, author.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes); corecommit.Committer = new GitSharp.Core.PersonIdent(committer.Name, committer.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes); corecommit.Message = message; corecommit.TreeEntry = tree.InternalTree; corecommit.Encoding = ExtractOverridenEncodingCommitFromConfig(repo); corecommit.Save(); return new Commit(repo, corecommit); }