Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'LibGit2Sharp/Repository.cs')
-rw-r--r--LibGit2Sharp/Repository.cs36
1 files changed, 28 insertions, 8 deletions
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 38cc0adb..019ee92e 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -893,14 +893,18 @@ namespace LibGit2Sharp
/// <param name="message">The description of why a change was made to the repository.</param>
/// <param name="author">The <see cref="Signature"/> of who made the change.</param>
/// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
- /// <param name="amendPreviousCommit">True to amend the current <see cref="Commit"/> pointed at by <see cref="Repository.Head"/>, false otherwise.</param>
- /// <param name="allowEmptyCommit">True to allow creation of an empty <see cref="Commit"/>, false otherwise.</param>
+ /// <param name="options">The <see cref="CommitOptions"/> that specify the commit behavior.</param>
/// <returns>The generated <see cref="Commit"/>.</returns>
- public Commit Commit(string message, Signature author, Signature committer, bool amendPreviousCommit = false, bool allowEmptyCommit = false)
+ public Commit Commit(string message, Signature author, Signature committer, CommitOptions options = null)
{
+ if (options == null)
+ {
+ options = new CommitOptions();
+ }
+
bool isHeadOrphaned = Info.IsHeadUnborn;
- if (amendPreviousCommit && isHeadOrphaned)
+ if (options.AmendPreviousCommit && isHeadOrphaned)
{
throw new UnbornBranchException("Can not amend anything. The Head doesn't point at any commit.");
}
@@ -908,12 +912,12 @@ namespace LibGit2Sharp
var treeId = Proxy.git_tree_create_fromindex(Index);
var tree = this.Lookup<Tree>(treeId);
- var parents = RetrieveParentsOfTheCommitBeingCreated(amendPreviousCommit).ToList();
+ var parents = RetrieveParentsOfTheCommitBeingCreated(options.AmendPreviousCommit).ToList();
- if (parents.Count == 1 && !allowEmptyCommit)
+ if (parents.Count == 1 && !options.AllowEmptyCommit)
{
var treesame = parents[0].Tree.Id.Equals(treeId);
- var amendMergeCommit = amendPreviousCommit && !isHeadOrphaned && Head.Tip.Parents.Count() > 1;
+ var amendMergeCommit = options.AmendPreviousCommit && !isHeadOrphaned && Head.Tip.Parents.Count() > 1;
if (treesame && !amendMergeCommit)
{
@@ -934,12 +938,28 @@ namespace LibGit2Sharp
return result;
}
- var logMessage = BuildCommitLogMessage(result, amendPreviousCommit, isHeadOrphaned, parents.Count > 1);
+ var logMessage = BuildCommitLogMessage(result, options.AmendPreviousCommit, isHeadOrphaned, parents.Count > 1);
LogCommit(result, logMessage);
return result;
}
+ /// <summary>
+ /// Stores the content of the <see cref="Repository.Index"/> as a new <see cref="Commit"/> into the repository.
+ /// The tip of the <see cref="Repository.Head"/> will be used as the parent of this new Commit.
+ /// Once the commit is created, the <see cref="Repository.Head"/> will move forward to point at it.
+ /// </summary>
+ /// <param name="message">The description of why a change was made to the repository.</param>
+ /// <param name="author">The <see cref="Signature"/> of who made the change.</param>
+ /// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
+ /// <param name="amendPreviousCommit">True to amend the current <see cref="Commit"/> pointed at by <see cref="Repository.Head"/>, false otherwise.</param>
+ /// <returns>The generated <see cref="Commit"/>.</returns>
+ [Obsolete("This method will be removed in the next release. Please use a Commit overload that accepts a CommitOptions instead.")]
+ public Commit Commit(string message, Signature author, Signature committer, bool amendPreviousCommit)
+ {
+ return Commit(message, author, committer, new CommitOptions { AmendPreviousCommit = amendPreviousCommit });
+ }
+
private string BuildCommitLogMessage(Commit commit, bool amendPreviousCommit, bool isHeadOrphaned, bool isMergeCommit)
{
string kind = string.Empty;