} // End Function GetRemoteBranchId // http://stackoverflow.com/questions/3407575/retrieving-oldest-commit-with-jgit public virtual System.DateTime GetLastCommitDate(string path) { System.DateTime retVal = default(System.DateTime); NGit.Revwalk.RevCommit c = null; NGit.Api.Git repository = NGit.Api.Git.Open(path); try { NGit.Revwalk.RevWalk rw = new NGit.Revwalk.RevWalk(repository.GetRepository()); NGit.AnyObjectId headid = repository.GetRepository().Resolve(NGit.Constants.HEAD); c = rw.ParseCommit(headid); // repository.GetRepository(). } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); } // Get author NGit.PersonIdent authorIdent = c.GetAuthorIdent(); System.DateTime authorDate = authorIdent.GetWhen(); retVal = authorDate.ToUniversalTime(); CloseRepository(repository); return(retVal); }
// http://stackoverflow.com/questions/3407575/retrieving-oldest-commit-with-jgit public virtual void GetOldestCommit(string path) { NGit.Revwalk.RevCommit c = null; NGit.Api.Git repository = NGit.Api.Git.Open(path); try { NGit.Revwalk.RevWalk rw = new NGit.Revwalk.RevWalk(repository.GetRepository()); NGit.AnyObjectId headid = repository.GetRepository().Resolve(NGit.Constants.HEAD); NGit.Revwalk.RevCommit root = rw.ParseCommit(headid); string msg1 = root.GetFullMessage(); rw.Sort(NGit.Revwalk.RevSort.REVERSE); rw.MarkStart(root); c = rw.Next(); // repository.GetRepository(). } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); } string msg2 = c.GetFullMessage(); // Get author NGit.PersonIdent authorIdent = c.GetAuthorIdent(); System.DateTime authorDate = authorIdent.GetWhen(); System.TimeZoneInfo authorTimeZone = authorIdent.GetTimeZone(); NGit.PersonIdent committerIdent = c.GetCommitterIdent(); // http://stackoverflow.com/questions/12608610/how-do-you-get-the-author-date-and-commit-date-from-a-jgit-revcommit System.Console.WriteLine(authorIdent); System.Console.WriteLine(authorDate); System.Console.WriteLine(authorTimeZone); System.Console.WriteLine(committerIdent); CloseRepository(repository); }
} // End Sub ListBranches // https://stackoverflow.com/questions/40590039/how-to-get-the-file-list-for-a-commit-with-jgit // https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/api/GetRevCommitFromObjectId.java public virtual void ListFilesIncmt(string path, NGit.Revwalk.RevCommit commit) { NGit.Api.Git repository = NGit.Api.Git.Open(path); NGit.ObjectId treeId = commit.Tree.Id; NGit.Treewalk.TreeWalk treeWalk = new NGit.Treewalk.TreeWalk(repository.GetRepository()); treeWalk.Reset(treeId); while (treeWalk.Next()) { string filePath = treeWalk.PathString; System.Console.WriteLine(filePath); } NGit.Ref @ref = repository.GetRepository().GetRef("refs/heads/master"); NGit.ObjectId head = @ref.GetObjectId(); using (NGit.Revwalk.RevWalk walk = new NGit.Revwalk.RevWalk(repository.GetRepository())) { NGit.Revwalk.RevCommit headCommit = walk.ParseCommit(head); } NGit.ObjectId commitIdFromHash = repository.GetRepository().Resolve("revstr"); }