diff options
author | Metalrom <romain.magny@gmail.com> | 2013-02-01 20:31:20 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-02-28 15:34:55 +0400 |
commit | 0ab83f0808a23a9ef199ec5cdc4eee69f13ccddf (patch) | |
tree | 6ce2e15e61a17513c0d2a86a365c55ead1853737 /LibGit2Sharp/StashCollection.cs | |
parent | 9dfa8c16770a5b41d4303c230d41c7eb4297be45 (diff) |
Add Repository.Stashes.Add
Diffstat (limited to 'LibGit2Sharp/StashCollection.cs')
-rw-r--r-- | LibGit2Sharp/StashCollection.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/LibGit2Sharp/StashCollection.cs b/LibGit2Sharp/StashCollection.cs new file mode 100644 index 00000000..f7db799b --- /dev/null +++ b/LibGit2Sharp/StashCollection.cs @@ -0,0 +1,51 @@ +using LibGit2Sharp.Core; + +namespace LibGit2Sharp +{ + /// <summary> + /// The collection of <see cref = "Stash" />es in a <see cref = "Repository" /> + /// </summary> + public class StashCollection + { + internal readonly Repository repo; + + /// <summary> + /// Needed for mocking purposes. + /// </summary> + protected StashCollection() + { } + + /// <summary> + /// Initializes a new instance of the <see cref = "StashCollection" /> class. + /// </summary> + /// <param name = "repo">The repo.</param> + internal StashCollection(Repository repo) + { + this.repo = repo; + } + + /// <summary> + /// Creates a stash with the specified message. + /// </summary> + /// <param name="stasher">The <see cref="Signature"/> of the user who stashes </param> + /// <param name = "message">The message of the stash.</param> + /// <param name = "options">A combination of <see cref="StashOptions"/> flags</param> + /// <returns>the newly created <see cref="Stash"/></returns> + public virtual Stash Add(Signature stasher, string message = null, StashOptions options = StashOptions.Default) + { + Ensure.ArgumentNotNull(stasher, "stasher"); + + string prettifiedMessage = Proxy.git_message_prettify(string.IsNullOrEmpty(message) ? string.Empty : message); + + ObjectId oid = Proxy.git_stash_save(repo.Handle, stasher, prettifiedMessage, options); + + // in case there is nothing to stash + if (oid == null) + { + return null; + } + + return new Stash(repo, oid); + } + } +} |