} // End Function Commit public virtual void CommitAndPush(string path) { // No empty commit if (!HasChanges(path)) { return; } NGit.Api.Git repository = NGit.Api.Git.Open(path); NGit.PersonIdent author = new NGit.PersonIdent("Lance Mcnearney", "*****@*****.**"); string message = "My commit message"; // Commit our changes after adding files to the stage NGit.Revwalk.RevCommit commit = repository.Commit() .SetMessage(message) .SetAuthor(author) .SetAll(true) // This automatically stages modified and deleted files .Call(); // Our new commit's hash NGit.ObjectId hash = commit.Id; // Push our changes back to the origin Sharpen.Iterable <NGit.Transport.PushResult> push = repository.Push().Call(); CloseRepository(repository); } // End Sub CommitAndPush
} // End Function Commit public virtual string Commit(string path, string message) { string commitId = null; // No empty commit if (!HasChanges(path)) { return(commitId); } NGit.Api.Git repository = NGit.Api.Git.Open(path); NGit.PersonIdent author = new NGit.PersonIdent("FooBar2000", "*****@*****.**"); // Commit our changes after adding files to the stage NGit.Revwalk.RevCommit commit = repository.Commit() .SetMessage(message) .SetAuthor(author) .SetAll(true) // This automatically stages modified and deleted files .Call(); // Our new commit's hash NGit.ObjectId hash = commit.Id; commitId = hash.Name; CloseRepository(repository); return(commitId); } // End Function Commit
} // 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); }