summaryrefslogtreecommitdiff
path: root/src/rebase.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-08-09 09:01:56 +0200
committerGitHub <noreply@github.com>2019-08-09 09:01:56 +0200
commitb0692d6b3e818b9389295d7d33a0601143cc0c16 (patch)
tree1ab0ec22115183c7215618a36b62f20e807281c2 /src/rebase.c
parentf627ba6c7f4b40d533cc127f408cbce8353697ed (diff)
parent998f9c15fdca34bbfe6a3d92093afe9c7f886dcf (diff)
downloadlibgit2-b0692d6b3e818b9389295d7d33a0601143cc0c16.tar.gz
Merge pull request #4913 from implausible/feature/signing-rebase-commits
Add sign capability to git_rebase_commit
Diffstat (limited to 'src/rebase.c')
-rw-r--r--src/rebase.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/rebase.c b/src/rebase.c
index fbba4bcb3..d171fa2aa 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -951,6 +951,10 @@ static int rebase_commit__create(
git_commit *current_commit = NULL, *commit = NULL;
git_tree *parent_tree = NULL, *tree = NULL;
git_oid tree_id, commit_id;
+ git_buf commit_content = GIT_BUF_INIT, commit_signature = GIT_BUF_INIT,
+ signature_field = GIT_BUF_INIT;
+ const char *signature_field_string = NULL,
+ *commit_signature_string = NULL;
int error;
operation = git_array_get(rebase->operations, rebase->current);
@@ -981,10 +985,40 @@ static int rebase_commit__create(
message = git_commit_message(current_commit);
}
- if ((error = git_commit_create(&commit_id, rebase->repo, NULL, author,
- committer, message_encoding, message, tree, 1,
- (const git_commit **)&parent_commit)) < 0 ||
- (error = git_commit_lookup(&commit, rebase->repo, &commit_id)) < 0)
+ if ((error = git_commit_create_buffer(&commit_content, rebase->repo, author, committer,
+ message_encoding, message, tree, 1, (const git_commit **)&parent_commit)) < 0)
+ goto done;
+
+ if (rebase->options.signing_cb) {
+ git_error_clear();
+ error = git_error_set_after_callback_function(rebase->options.signing_cb(
+ &commit_signature, &signature_field, git_buf_cstr(&commit_content),
+ rebase->options.payload), "commit signing_cb failed");
+ if (error == GIT_PASSTHROUGH) {
+ git_buf_dispose(&commit_signature);
+ git_buf_dispose(&signature_field);
+ git_error_clear();
+ error = GIT_OK;
+ } else if (error < 0)
+ goto done;
+ }
+
+ if (git_buf_is_allocated(&commit_signature)) {
+ assert(git_buf_contains_nul(&commit_signature));
+ commit_signature_string = git_buf_cstr(&commit_signature);
+ }
+
+ if (git_buf_is_allocated(&signature_field)) {
+ assert(git_buf_contains_nul(&signature_field));
+ signature_field_string = git_buf_cstr(&signature_field);
+ }
+
+ if ((error = git_commit_create_with_signature(&commit_id, rebase->repo,
+ git_buf_cstr(&commit_content), commit_signature_string,
+ signature_field_string)))
+ goto done;
+
+ if ((error = git_commit_lookup(&commit, rebase->repo, &commit_id)) < 0)
goto done;
*out = commit;
@@ -993,6 +1027,9 @@ done:
if (error < 0)
git_commit_free(commit);
+ git_buf_dispose(&commit_signature);
+ git_buf_dispose(&signature_field);
+ git_buf_dispose(&commit_content);
git_commit_free(current_commit);
git_tree_free(parent_tree);
git_tree_free(tree);