diff --git a/GitUpKit/Core/GCRepository+Bare.m b/GitUpKit/Core/GCRepository+Bare.m index b933d1a2..b53041fc 100644 --- a/GitUpKit/Core/GCRepository+Bare.m +++ b/GitUpKit/Core/GCRepository+Bare.m @@ -376,23 +376,21 @@ - (GCCommit*)createCommitFromTree:(git_tree*)tree CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_signature_default, &signature, self.private); git_buf commitBuffer = GIT_BUF_INIT; - CALL_LIBGIT2_FUNCTION_GOTO(cleanupBuffer, git_commit_create_buffer, &commitBuffer, self.private, author ? author : signature, signature, NULL, GCCleanedUpCommitMessage(message).bytes, tree, count, parents); + CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_create_buffer, &commitBuffer, self.private, author ? author : signature, signature, NULL, GCCleanedUpCommitMessage(message).bytes, tree, count, parents); if (shouldSign) { GCConfigOption* signingKeyOption = [self readConfigOptionForVariable:@"user.signingkey" error:nil]; gpgSignature = [self gpgSig:commitBuffer.ptr keyId:signingKeyOption.value]; } - CALL_LIBGIT2_FUNCTION_GOTO(cleanupBuffer, git_commit_create_with_signature, &oid, self.private, commitBuffer.ptr, gpgSignature, NULL); + CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_create_with_signature, &oid, self.private, commitBuffer.ptr, gpgSignature, NULL); git_commit* newCommit = NULL; CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_lookup, &newCommit, self.private, &oid); commit = [[GCCommit alloc] initWithRepository:self commit:newCommit]; -cleanupBuffer: - git_buf_dispose(&commitBuffer); - cleanup: + git_buf_dispose(&commitBuffer); git_signature_free(signature); return commit; } @@ -479,20 +477,36 @@ - (GCCommit*)createCommitFromCommit:(git_commit*)commit git_signature* signature = NULL; git_oid oid; + GCConfigOption* shouldSignOption = [self readConfigOptionForVariable:@"commit.gpgsign" error:nil]; + if (updateCommitter) { CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_signature_default, &signature, self.private); } - CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_create_from_callback, &oid, self.private, NULL, + git_buf commitBuffer = GIT_BUF_INIT; + CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_create_buffer_for_parents_cb, &commitBuffer, self.private, git_commit_author(commit), updateCommitter ? signature : git_commit_committer(commit), - message ? NULL : git_commit_message_encoding(commit), message ? GCCleanedUpCommitMessage(message).bytes : git_commit_message(commit), + message ? NULL : git_commit_message_encoding(commit), + message ? GCCleanedUpCommitMessage(message).bytes : git_commit_message(commit), git_tree_id(tree), - parents ? _CommitParentCallback_Parents : _CommitParentCallback_Commit, parents ? (__bridge void*)parents : (void*)commit); + parents ? _CommitParentCallback_Parents : _CommitParentCallback_Commit, parents ? (__bridge void*)parents : (void*)commit, + true); + + const char *gpgSignature = NULL; + if ([shouldSignOption.value isEqualToString:@"true"]) { + GCConfigOption* signingKeyOption = [self readConfigOptionForVariable:@"user.signingkey" error:nil]; + + gpgSignature = [self gpgSig:commitBuffer.ptr keyId:signingKeyOption.value]; + } + + CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_create_with_signature, &oid, self.private, commitBuffer.ptr, gpgSignature, NULL); + CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_lookup, &newCommit, self.private, &oid); XLOG_DEBUG_CHECK(!git_oid_equal(git_commit_id(newCommit), git_commit_id(commit))); cleanup: + git_buf_dispose(&commitBuffer); git_signature_free(signature); return newCommit ? [[GCCommit alloc] initWithRepository:self commit:newCommit] : nil; } diff --git a/GitUpKit/Third-Party/libgit2 b/GitUpKit/Third-Party/libgit2 index d7392521..4b144831 160000 --- a/GitUpKit/Third-Party/libgit2 +++ b/GitUpKit/Third-Party/libgit2 @@ -1 +1 @@ -Subproject commit d7392521782deb1ff59c21da64df137bf64e9d53 +Subproject commit 4b1448311b7c0b666273ebe37c998e331a1c95df