private void OnCommitted(CommitResult commitResult) => Committed?.Invoke(this, new CommitResultEventArgs(commitResult));
/* * git commit [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run] [(-c | -C) <commit>] * [-F <file> | -m <msg>] [--reset-author] [--allow-empty] [--no-verify] [-e] [--author=<author>] * [--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--] [[-i | -o ]<file>…] */ public CommitResult Commit(string message, bool amend = false) { Verify.Argument.IsNotNull(message, nameof(message)); var currentBranch = Repository.Head.Pointer as Branch; var output = default(string); using (Repository.Monitor.BlockNotifications( RepositoryNotifications.IndexUpdated, RepositoryNotifications.BranchChanged, RepositoryNotifications.Checkout)) { var fileName = Path.Combine( Repository.GitDirectory, GitConstants.CommitMessageFileName); File.WriteAllText(fileName, message); bool commitSuccess = false; try { output = Repository.Accessor.Commit.Invoke( new CommitParameters { MessageFileName = Path.Combine( Repository.GitDirectory, GitConstants.CommitMessageFileName), Amend = amend, }); commitSuccess = true; } finally { if (commitSuccess) { try { File.Delete(fileName); } catch (Exception exc) when(!exc.IsCritical()) { } } } } Revision commit = null; if (currentBranch != null) { var oldHeadRev = currentBranch.Revision; currentBranch.Refresh(); commit = currentBranch.Revision; if (commit != oldHeadRev) { Repository.OnCommitCreated(commit); } } else { var oldHeadRev = Repository.Head.Revision; Repository.Head.Refresh(); commit = Repository.Head.Revision; if (commit != oldHeadRev) { Repository.OnCommitCreated(commit); } } Repository.Head.NotifyRelogRecordAdded(); Repository.OnStateChanged(); Refresh(); var result = new CommitResult(commit, output); OnCommitted(result); return(result); }
public CommitResultEventArgs(CommitResult commitResult) { CommitResult = commitResult; }