public Commit GetCommit(string commitId) { //commitId = repository.Resolve(commitId).Name; //return Commits.Where(c => c.Id.StartsWith(commitId)).FirstOrDefault(); var id = repository.Resolve(commitId); if (id == null) { return(null); } RevWalk walk = new RevWalk(repository); RevCommit commit = walk.ParseCommit(id); walk.Dispose(); return(commit == null || commit.Tree == null ? null : new Commit { Id = commit.Id.Name, ParentIds = commit.Parents.Select(p => p.Id.Name).ToList(), CommitDateRelative = RelativeDateFormatter.Format(commit.GetAuthorIdent().GetWhen()), CommitterName = commit.GetCommitterIdent().GetName(), CommitterEmail = commit.GetCommitterIdent().GetEmailAddress(), CommitDate = commit.GetCommitterIdent().GetWhen(), Message = commit.GetShortMessage(), }); }
private static Commit ToCommit(RevCommit commit, Repository repository) { return(new Commit ( repository, commit.Name, commit.GetShortMessage(), ToPerson(commit.GetAuthorIdent()), ToPerson(commit.GetCommitterIdent()), commit.GetCommitterIdent().GetWhen(), commit.Parents.Select(p => p.Name) )); }
/// <summary>Core validation to be performed on all stashed commits</summary> /// <param name="commit"></param> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> private void ValidateStashedCommit(RevCommit commit) { NUnit.Framework.Assert.IsNotNull(commit); Ref stashRef = db.GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNotNull(stashRef); NUnit.Framework.Assert.AreEqual(commit, stashRef.GetObjectId()); NUnit.Framework.Assert.IsNotNull(commit.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(commit.GetAuthorIdent(), commit.GetCommitterIdent ()); NUnit.Framework.Assert.AreEqual(2, commit.ParentCount); // Load parents RevWalk walk = new RevWalk(db); try { foreach (RevCommit parent in commit.Parents) { walk.ParseBody(parent); } } finally { walk.Release(); } NUnit.Framework.Assert.AreEqual(1, commit.GetParent(1).ParentCount); NUnit.Framework.Assert.AreEqual(head, commit.GetParent(1).GetParent(0)); NUnit.Framework.Assert.IsFalse(commit.Tree.Equals(head.Tree), "Head tree matches stashed commit tree" ); NUnit.Framework.Assert.AreEqual(head, commit.GetParent(0)); NUnit.Framework.Assert.IsFalse(commit.GetFullMessage().Equals(commit.GetParent(1) .GetFullMessage())); }
public override CommitInfo GetLatestCommit() { using (var repository = GetRepository()) { var repo = (FileRepository)repository; var branch = repo.GetBranch(); if (branch == null) { return(null); } var objId = repo.Resolve(branch); if (objId == null) { return(null); } RevWalk walk = new RevWalk(repo); RevCommit commit = walk.ParseCommit(objId); if (commit == null) { return(null); } return(new CommitInfo { Message = commit.GetFullMessage(), Date = commit.GetCommitterIdent().GetWhen().ToLocalTime() }); } }
public static PersonIdent committer(this RevCommit revCommit) { if (revCommit.notNull()) { return(revCommit.GetCommitterIdent()); } return(null); }
public virtual void Test009_CreateCommitOldFormat() { ObjectId treeId = InsertTree(new TreeFormatter()); NGit.CommitBuilder c = new NGit.CommitBuilder(); c.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c.Message = "A Commit\n"; c.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c.TreeId); ObjectId actid = InsertCommit(c); ObjectId cmtid = ObjectId.FromString("9208b2459ea6609a5af68627cc031796d0d9329b"); NUnit.Framework.Assert.AreEqual(cmtid, actid); // Verify the commit we just wrote is in the correct format. ObjectDatabase odb = ((ObjectDirectory)db.ObjectDatabase); NUnit.Framework.Assert.IsTrue(odb is ObjectDirectory, "is ObjectDirectory"); XInputStream xis = new XInputStream(new FileInputStream(((ObjectDirectory)odb).FileFor (cmtid))); try { NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x78)), xis.ReadUInt8()); NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x9c)), xis.ReadUInt8()); NUnit.Framework.Assert.IsTrue(unchecked ((int)(0x789c)) % 31 == 0); } finally { xis.Close(); } // Verify we can read it. RevCommit c2 = ParseCommit(actid); NUnit.Framework.Assert.IsNotNull(c2); NUnit.Framework.Assert.AreEqual(c.Message, c2.GetFullMessage()); NUnit.Framework.Assert.AreEqual(c.TreeId, c2.Tree); NUnit.Framework.Assert.AreEqual(c.Author, c2.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(c.Committer, c2.GetCommitterIdent()); }
/// <returns>current committer being blamed.</returns> public virtual PersonIdent GetSourceCommitter() { RevCommit c = GetSourceCommit(); return(c != null?c.GetCommitterIdent() : null); }
public static DateTime GetCommitTime(this RevCommit commit) { return(commit.GetCommitterIdent().GetWhen()); }