Skip to content

Commit 5211f8f

Browse files
committed
Support signing for rebased changes
1 parent 177d80d commit 5211f8f

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

Diff for: GitUpKit/Core/GCRepository+Bare.m

+40-2
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ - (GCCommit*)createCommitFromTree:(git_tree*)tree
387387

388388
if (gpgSignature != NULL) {
389389
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("!");
390394
} else {
391395
CALL_LIBGIT2_FUNCTION_GOTO(cleanupBuffer, git_commit_create, &oid, self.private, NULL, author ? author : signature, signature, NULL, GCCleanedUpCommitMessage(message).bytes, tree, count, parents);
392396
}
@@ -458,6 +462,14 @@ - (GCCommit*)createCommitFromIndex:(git_index*)index
458462
return NULL;
459463
}
460464

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+
461473
- (GCCommit*)createCommitFromCommit:(git_commit*)commit
462474
withIndex:(git_index*)index
463475
updatedMessage:(NSString*)message
@@ -483,14 +495,38 @@ - (GCCommit*)createCommitFromCommit:(git_commit*)commit
483495
git_signature* signature = NULL;
484496
git_oid oid;
485497

498+
GCConfigOption* shouldSignOption = [self readConfigOptionForVariable:@"commit.gpgsign" error:nil];
499+
486500
if (updateCommitter) {
487501
CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_signature_default, &signature, self.private);
488502
}
489503

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,
491506
git_commit_author(commit),
492507
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,
494530
git_tree_id(tree),
495531
parents ? _CommitParentCallback_Parents : _CommitParentCallback_Commit, parents ? (__bridge void*)parents : (void*)commit);
496532
CALL_LIBGIT2_FUNCTION_GOTO(cleanup, git_commit_lookup, &newCommit, self.private, &oid);
@@ -502,3 +538,5 @@ - (GCCommit*)createCommitFromCommit:(git_commit*)commit
502538
}
503539

504540
@end
541+
542+

Diff for: GitUpKit/GitUpKit.xcodeproj/project.pbxproj

+1
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,7 @@
18921892
"$(inherited)",
18931893
"$(PROJECT_DIR)",
18941894
);
1895+
GCC_OPTIMIZATION_LEVEL = s;
18951896
HEADER_SEARCH_PATHS = (
18961897
"Third-Party/libgit2/include",
18971898
"Third-Party/libsqlite3/$(PLATFORM_NAME)/include",

Diff for: GitUpKit/Third-Party/libgit2.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
E2174F461B912B6B00BE234A /* cherrypick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cherrypick.c; sourceTree = "<group>"; };
326326
E2174F471B912B6B00BE234A /* clone.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = clone.c; sourceTree = "<group>"; };
327327
E2174F481B912B6B00BE234A /* clone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = clone.h; sourceTree = "<group>"; };
328-
E2174F491B912B6B00BE234A /* commit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = commit.c; sourceTree = "<group>"; };
328+
E2174F491B912B6B00BE234A /* commit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = commit.c; sourceTree = "<group>"; usesTabs = 1; };
329329
E2174F4A1B912B6B00BE234A /* commit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = commit.h; sourceTree = "<group>"; };
330330
E2174F4B1B912B6B00BE234A /* commit_list.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = commit_list.c; sourceTree = "<group>"; };
331331
E2174F4C1B912B6B00BE234A /* commit_list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = commit_list.h; sourceTree = "<group>"; };

0 commit comments

Comments
 (0)