Skip to content

Commit

Permalink
Sign commits in advanced operations
Browse files Browse the repository at this point in the history
  • Loading branch information
OdNairy committed Sep 26, 2022
1 parent 7e17d4e commit 96d073e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
25 changes: 23 additions & 2 deletions GitUpKit/Core/GCRepository+Bare.m
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ - (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(cleanupBuffer, git_commit_create_buffer, &commitBuffer, self.private, author ? author : signature, signature, NULL, GCCleanedUpCommitMessage(message).bytes, NULL, tree, count, parents);

if (shouldSign) {
GCConfigOption* signingKeyOption = [self readConfigOptionForVariable:@"user.signingkey" error:nil];
Expand Down Expand Up @@ -479,14 +479,35 @@ - (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);
}

git_buf commitBuffer = GIT_BUF_INIT;
CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_create_buffer_for_signature, &commitBuffer, &oid, self.private, NULL,
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),
git_tree_id(tree),
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_from_callback, &oid, self.private, NULL,
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),
gpgSignature,
git_tree_id(tree),
parents ? _CommitParentCallback_Parents : _CommitParentCallback_Commit, parents ? (__bridge void*)parents : (void*)commit);
CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_lookup, &newCommit, self.private, &oid);
Expand Down
2 changes: 1 addition & 1 deletion GitUpKit/Core/GCRepository+Mock.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ - (NSArray*)createMockCommitHierarchyFromNotation:(NSString*)notation force:(BOO
CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_signature_new, &signature, "user", "[email protected]", NSTimeIntervalSince1970 + commits.count, 0);
git_oid oid;
void* params[] = {cache, (__bridge void*)parents};
CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_create_from_callback, &oid, self.private, NULL, signature, signature, NULL, message.UTF8String, &treeOID, _CommitParentCallback, params);
CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_create_from_callback, &oid, self.private, NULL, signature, signature, NULL, message.UTF8String, NULL, &treeOID, _CommitParentCallback, params);
git_signature_free(signature);
signature = NULL;
git_commit* emptyCommit;
Expand Down
2 changes: 1 addition & 1 deletion GitUpKit/Third-Party/libgit2

0 comments on commit 96d073e

Please sign in to comment.