@@ -387,6 +387,10 @@ - (GCCommit*)createCommitFromTree:(git_tree*)tree
387
387
388
388
if (gpgSignature != NULL ) {
389
389
CALL_LIBGIT2_FUNCTION_GOTO (cleanupBuffer, git_commit_create_with_signature, &oid, self.private , commitBuffer.ptr , gpgSignature, NULL );
390
+
391
+ git_commit* signed_commit = nil ;
392
+ git_commit_lookup (&signed_commit, self.private , &oid);
393
+ printf (" !" );
390
394
} else {
391
395
CALL_LIBGIT2_FUNCTION_GOTO (cleanupBuffer, git_commit_create, &oid, self.private , NULL , author ? author : signature, signature, NULL , GCCleanedUpCommitMessage (message).bytes , tree, count, parents);
392
396
}
@@ -458,6 +462,14 @@ - (GCCommit*)createCommitFromIndex:(git_index*)index
458
462
return NULL ;
459
463
}
460
464
465
+ static int (_SignCommitCallback)(git_buf *signature, git_buf *signature_field, const char *commit_content, void *payload) {
466
+ // Cannot implement such signing callback
467
+ // Reason: We need access to self for gpg signing method, key, configs and repo information.
468
+
469
+
470
+ return GIT_OK;
471
+ }
472
+
461
473
- (GCCommit*)createCommitFromCommit : (git_commit*)commit
462
474
withIndex : (git_index*)index
463
475
updatedMessage : (NSString *)message
@@ -483,14 +495,38 @@ - (GCCommit*)createCommitFromCommit:(git_commit*)commit
483
495
git_signature* signature = NULL ;
484
496
git_oid oid;
485
497
498
+ GCConfigOption* shouldSignOption = [self readConfigOptionForVariable: @" commit.gpgsign" error: nil ];
499
+
486
500
if (updateCommitter) {
487
501
CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_signature_default, &signature, self.private );
488
502
}
489
503
490
- CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_create_from_callback, &oid, self.private , NULL ,
504
+ git_buf commitBuffer = GIT_BUF_INIT_CONST (" " , 0 );
505
+ CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_create_buffer_for_signature, &commitBuffer, &oid, self.private , NULL ,
491
506
git_commit_author (commit),
492
507
updateCommitter ? signature : git_commit_committer (commit),
493
- message ? NULL : git_commit_message_encoding (commit), message ? GCCleanedUpCommitMessage (message).bytes : git_commit_message (commit),
508
+ message ? NULL : git_commit_message_encoding (commit),
509
+ message ? GCCleanedUpCommitMessage (message).bytes : git_commit_message (commit),
510
+ git_tree_id (tree),
511
+ parents ? _CommitParentCallback_Parents : _CommitParentCallback_Commit, parents ? (__bridge void *)parents : (void *)commit,
512
+ true );
513
+
514
+ const char *gpgSignature = NULL ;
515
+ if ([shouldSignOption.value isEqualToString: @" true" ]) {
516
+ GCConfigOption* signingKeyOption = [self readConfigOptionForVariable: @" user.signingkey" error: nil ];
517
+
518
+ gpgSignature = [self gpgSig: commitBuffer.ptr keyId: signingKeyOption.value];
519
+ }
520
+
521
+ printf (" signature?" );
522
+
523
+
524
+ CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_create_with_signature_from_callback, &oid, self.private , NULL ,
525
+ git_commit_author (commit),
526
+ updateCommitter ? signature : git_commit_committer (commit),
527
+ message ? NULL : git_commit_message_encoding (commit),
528
+ message ? GCCleanedUpCommitMessage (message).bytes : git_commit_message (commit),
529
+ gpgSignature,
494
530
git_tree_id (tree),
495
531
parents ? _CommitParentCallback_Parents : _CommitParentCallback_Commit, parents ? (__bridge void *)parents : (void *)commit);
496
532
CALL_LIBGIT2_FUNCTION_GOTO (cleanup, git_commit_lookup, &newCommit, self.private , &oid);
@@ -502,3 +538,5 @@ - (GCCommit*)createCommitFromCommit:(git_commit*)commit
502
538
}
503
539
504
540
@end
541
+
542
+
0 commit comments