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:
authorEdward Thomson <ethomson@microsoft.com>2014-04-09 19:19:06 +0400
committerEdward Thomson <ethomson@microsoft.com>2014-04-09 21:00:52 +0400
commitbd85a5b8557e27105d6476c83486516c73b95cd9 (patch)
treebb996ab1277b2cd13857a91d241ad58930c4022c /LibGit2Sharp
parent8a303f2b24a053816d8d88c3733447ae5565e662 (diff)
Introduce CommitOptions
Repository#Commit (and its extension methods) now take CommitOptions. All prior methods are deprecated.
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r--LibGit2Sharp/CommitOptions.cs26
-rw-r--r--LibGit2Sharp/IRepository.cs16
-rw-r--r--LibGit2Sharp/LibGit2Sharp.csproj1
-rw-r--r--LibGit2Sharp/Repository.cs36
-rw-r--r--LibGit2Sharp/RepositoryExtensions.cs45
5 files changed, 109 insertions, 15 deletions
diff --git a/LibGit2Sharp/CommitOptions.cs b/LibGit2Sharp/CommitOptions.cs
new file mode 100644
index 00000000..ce20a50a
--- /dev/null
+++ b/LibGit2Sharp/CommitOptions.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// Provides optional additional information to commit creation.
+ /// By default, a new commit will be created (instead of amending the
+ /// HEAD commit) and an empty commit which is unchanged from the current
+ /// HEAD is disallowed.
+ /// </summary>
+ public sealed class CommitOptions
+ {
+ /// <summary>
+ /// True to amend the current <see cref="Commit"/> pointed at by <see cref="Repository.Head"/>, false otherwise.
+ /// </summary>
+ public bool AmendPreviousCommit { get; set; }
+
+ /// <summary>
+ /// True to allow creation of an empty <see cref="Commit"/>, false otherwise.
+ /// </summary>
+ public bool AllowEmptyCommit { get; set; }
+ }
+}
diff --git a/LibGit2Sharp/IRepository.cs b/LibGit2Sharp/IRepository.cs
index 75e87b8b..61c96930 100644
--- a/LibGit2Sharp/IRepository.cs
+++ b/LibGit2Sharp/IRepository.cs
@@ -163,10 +163,22 @@ 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="options">The <see cref="CommitOptions"/> that specify the commit behavior.</param>
+ /// <returns>The generated <see cref="Commit"/>.</returns>
+ Commit Commit(string message, Signature author, Signature committer, CommitOptions options = null);
+
+ /// <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>
- /// <param name="allowEmptyCommit">True to allow creation of an empty <see cref="Commit"/>, false otherwise.</param>
/// <returns>The generated <see cref="Commit"/>.</returns>
- Commit Commit(string message, Signature author, Signature committer, bool amendPreviousCommit = false, bool allowEmptyCommit = false);
+ [Obsolete("This method will be removed in the next release. Please use a Commit overload that accepts a CommitOptions instead.")]
+ Commit Commit(string message, Signature author, Signature committer, bool amendPreviousCommit);
/// <summary>
/// Sets the current <see cref="Head"/> to the specified commit and optionally resets the <see cref="Index"/> and
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 08311890..47153bc9 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -74,6 +74,7 @@
<Compile Include="CheckoutOptions.cs" />
<Compile Include="CloneOptions.cs" />
<Compile Include="CommitFilter.cs" />
+ <Compile Include="CommitOptions.cs" />
<Compile Include="CommitSortStrategies.cs" />
<Compile Include="CompareOptions.cs" />
<Compile Include="ContentChangeStats.cs" />
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;
diff --git a/LibGit2Sharp/RepositoryExtensions.cs b/LibGit2Sharp/RepositoryExtensions.cs
index 82742350..d6e751b2 100644
--- a/LibGit2Sharp/RepositoryExtensions.cs
+++ b/LibGit2Sharp/RepositoryExtensions.cs
@@ -204,13 +204,31 @@ namespace LibGit2Sharp
/// </summary>
/// <param name="repository">The <see cref="Repository"/> being worked with.</param>
/// <param name="message">The description of why a change was made to the repository.</param>
+ /// <param name="options">The <see cref="CommitOptions"/> that specify the commit behavior.</param>
+ /// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns>
+ public static Commit Commit(this IRepository repository, string message, CommitOptions options = null)
+ {
+ Signature author = repository.Config.BuildSignature(DateTimeOffset.Now, true);
+
+ return repository.Commit(message, author, options);
+ }
+
+ /// <summary>
+ /// Stores the content of the <see cref="Repository.Index"/> as a new <see cref="LibGit2Sharp.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.
+ /// <para>Both the Author and Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable.</para>
+ /// </summary>
+ /// <param name="repository">The <see cref="Repository"/> being worked with.</param>
+ /// <param name="message">The description of why a change was made to the repository.</param>
/// <param name="amendPreviousCommit">True to amend the current <see cref="LibGit2Sharp.Commit"/> pointed at by <see cref="Repository.Head"/>, false otherwise.</param>
/// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns>
- public static Commit Commit(this IRepository repository, string message, bool amendPreviousCommit = false)
+ [Obsolete("This method will be removed in the next release. Please use a Commit overload that accepts a CommitOptions instead.")]
+ public static Commit Commit(this IRepository repository, string message, bool amendPreviousCommit)
{
Signature author = repository.Config.BuildSignature(DateTimeOffset.Now, true);
- return repository.Commit(message, author, amendPreviousCommit);
+ return repository.Commit(message, author, new CommitOptions { AmendPreviousCommit = amendPreviousCommit });
}
/// <summary>
@@ -222,13 +240,30 @@ namespace LibGit2Sharp
/// <param name="repository">The <see cref="Repository"/> being worked with.</param>
/// <param name="author">The <see cref="Signature"/> of who made the change.</param>
/// <param name="message">The description of why a change was made to the repository.</param>
- /// <param name="amendPreviousCommit">True to amend the current <see cref="LibGit2Sharp.Commit"/> pointed at by <see cref="Repository.Head"/>, false otherwise.</param>
+ /// <param name="options">The <see cref="CommitOptions"/> that specify the commit behavior.</param>
/// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns>
- public static Commit Commit(this IRepository repository, string message, Signature author, bool amendPreviousCommit = false)
+ public static Commit Commit(this IRepository repository, string message, Signature author, CommitOptions options = null)
{
Signature committer = repository.Config.BuildSignature(DateTimeOffset.Now, true);
- return repository.Commit(message, author, committer, amendPreviousCommit);
+ return repository.Commit(message, author, committer, options);
+ }
+
+ /// <summary>
+ /// Stores the content of the <see cref="Repository.Index"/> as a new <see cref="LibGit2Sharp.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.
+ /// <para>The Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable.</para>
+ /// </summary>
+ /// <param name="repository">The <see cref="Repository"/> being worked with.</param>
+ /// <param name="author">The <see cref="Signature"/> of who made the change.</param>
+ /// <param name="message">The description of why a change was made to the repository.</param>
+ /// <param name="amendPreviousCommit">True to amend the current <see cref="LibGit2Sharp.Commit"/> pointed at by <see cref="Repository.Head"/>, false otherwise.</param>
+ /// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns>
+ [Obsolete("This method will be removed in the next release. Please use a Commit overload that accepts a CommitOptions instead.")]
+ public static Commit Commit(this IRepository repository, string message, Signature author, bool amendPreviousCommit)
+ {
+ return repository.Commit(message, author, new CommitOptions { AmendPreviousCommit = amendPreviousCommit });
}
/// <summary>