@@ -238,6 +238,7 @@ static BOOL _LooksLikeInlineSSHKey(NSString* key) {
238238 git_signature* signature = NULL ;
239239 git_commit* newCommit = NULL ;
240240 NSData * cleanedMessage = nil ;
241+ const char * cleanedMessageBytes = NULL ;
241242#if !TARGET_OS_IPHONE
242243 git_buf commitBuffer = {0 };
243244 NSData * commitData = nil ;
@@ -249,13 +250,14 @@ static BOOL _LooksLikeInlineSSHKey(NSString* key) {
249250 CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_signature_default, &signature, repository.private );
250251 authorSignature = author ?: signature;
251252 cleanedMessage = GCCleanedUpCommitMessage (message);
253+ cleanedMessageBytes = (const char *)cleanedMessage.bytes ;
252254#if !TARGET_OS_IPHONE
253255 if (!_ShouldSSHSignCommit (repository, &shouldSign, error)) {
254256 goto cleanup;
255257 }
256258
257259 if (shouldSign) {
258- CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_create_buffer, &commitBuffer, repository.private , authorSignature, signature, NULL , cleanedMessage. bytes , tree, count, parents);
260+ CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_create_buffer, &commitBuffer, repository.private , authorSignature, signature, NULL , cleanedMessageBytes , tree, count, parents);
259261 commitData = [[NSData alloc ] initWithBytes: commitBuffer.ptr length: commitBuffer.size];
260262 sshSignature = _SSHSignatureForCommitBuffer (repository, commitData, error);
261263 if (!sshSignature) {
@@ -264,7 +266,7 @@ static BOOL _LooksLikeInlineSSHKey(NSString* key) {
264266 CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_create_with_signature, &oid, repository.private , commitBuffer.ptr , sshSignature.UTF8String , " gpgsig" );
265267 } else {
266268#endif
267- CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_create, &oid, repository.private , NULL , authorSignature, signature, NULL , cleanedMessage. bytes , tree, count, parents);
269+ CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_create, &oid, repository.private , NULL , authorSignature, signature, NULL , cleanedMessageBytes , tree, count, parents);
268270#if !TARGET_OS_IPHONE
269271 }
270272#endif
@@ -280,3 +282,40 @@ static BOOL _LooksLikeInlineSSHKey(NSString* key) {
280282 git_signature_free (signature);
281283 return commit;
282284}
285+
286+ GCCommit* GCCreateCommitFromCommitWithIndexAndOptionalSignature (GCRepository* repository, git_commit* amendedCommit, git_index* index, NSString * message, NSError ** error) {
287+ GCCommit* commit = nil ;
288+ git_tree* tree = NULL ;
289+ git_commit** parentCommits = NULL ;
290+ unsigned int parentCount = 0 ;
291+ const git_commit** parents = NULL ;
292+
293+ git_oid oid;
294+ CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_index_write_tree_to, &oid, index, repository.private );
295+ CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_tree_lookup, &tree, repository.private , &oid);
296+
297+ parentCount = git_commit_parentcount (amendedCommit);
298+ if (parentCount) {
299+ parentCommits = (git_commit**)calloc (parentCount, sizeof (git_commit*));
300+ if (!parentCommits) {
301+ GC_SET_GENERIC_ERROR (@" Unable to allocate commit parent list" );
302+ goto cleanup;
303+ }
304+ for (unsigned int i = 0 ; i < parentCount; ++i) {
305+ CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_parent, &parentCommits[i], amendedCommit, i);
306+ }
307+ }
308+ parents = (const git_commit**)parentCommits;
309+
310+ commit = GCCreateCommitFromTreeWithOptionalSignature (repository, tree, parents, parentCount, git_commit_author (amendedCommit), message, error);
311+
312+ cleanup:
313+ if (parentCommits) {
314+ for (unsigned int i = 0 ; i < parentCount; ++i) {
315+ git_commit_free (parentCommits[i]);
316+ }
317+ free (parentCommits);
318+ }
319+ git_tree_free (tree);
320+ return commit;
321+ }
0 commit comments