@@ -150,6 +150,44 @@ public static SignatureInfo ExtractSignature(Repository repo, ObjectId id)
150
150
return Proxy . git_commit_extract_signature ( repo . Handle , id , null ) ;
151
151
}
152
152
153
+ /// <summary>
154
+ /// Create a commit in-memroy
155
+ /// <para>
156
+ /// Prettifing the message includes:
157
+ /// * Removing empty lines from the beginning and end.
158
+ /// * Removing trailing spaces from every line.
159
+ /// * Turning multiple consecutive empty lines between paragraphs into just one empty line.
160
+ /// * Ensuring the commit message ends with a newline.
161
+ /// * Removing every line starting with the <paramref name="commentChar"/>.
162
+ /// </para>
163
+ /// </summary>
164
+ /// <param name="author">The <see cref="Signature"/> of who made the change.</param>
165
+ /// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
166
+ /// <param name="message">The description of why a change was made to the repository.</param>
167
+ /// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param>
168
+ /// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param>
169
+ /// <param name="prettifyMessage">True to prettify the message, or false to leave it as is.</param>
170
+ /// <param name="commentChar">When non null, lines starting with this character will be stripped if prettifyMessage is true.</param>
171
+ /// <returns>The contents of the commit object.</returns>
172
+ public static string CreateBuffer ( Signature author , Signature committer , string message , Tree tree , IEnumerable < Commit > parents , bool prettifyMessage , char ? commentChar )
173
+ {
174
+ Ensure . ArgumentNotNull ( message , "message" ) ;
175
+ Ensure . ArgumentDoesNotContainZeroByte ( message , "message" ) ;
176
+ Ensure . ArgumentNotNull ( author , "author" ) ;
177
+ Ensure . ArgumentNotNull ( committer , "committer" ) ;
178
+ Ensure . ArgumentNotNull ( tree , "tree" ) ;
179
+ Ensure . ArgumentNotNull ( parents , "parents" ) ;
180
+
181
+ if ( prettifyMessage )
182
+ {
183
+ message = Proxy . git_message_prettify ( message , commentChar ) ;
184
+ }
185
+ var treeHandle = Proxy . git_object_lookup ( tree . repo . Handle , tree . Id , GitObjectType . Tree ) ;
186
+ var handles = parents . Select ( c => Proxy . git_object_lookup ( c . repo . Handle , c . Id , GitObjectType . Commit ) ) ;
187
+
188
+ return Proxy . git_commit_create_buffer ( tree . repo . Handle , author , committer , message , treeHandle , handles . ToArray ( ) ) ;
189
+ }
190
+
153
191
private class ParentsCollection : ICollection < Commit >
154
192
{
155
193
private readonly Lazy < ICollection < Commit > > _parents ;
0 commit comments