commit: git_commit_create_with_signature should support null signature

If provided with a null signature, skip adding the signature header and create the commit anyway.
parent 3b8a6f43
......@@ -480,7 +480,8 @@ GIT_EXTERN(int) git_commit_create_buffer(
*
* @param out the resulting commit id
* @param commit_content the content of the unsigned commit object
* @param signature the signature to add to the commit
* @param signature the signature to add to the commit. Leave `NULL`
* to create a commit without adding a signature field.
* @param signature_field which header field should contain this
* signature. Leave `NULL` for the default of "gpgsig"
* @return 0 or an error code
......
......@@ -80,8 +80,8 @@ on_error:
}
static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *repo, const git_oid *tree,
git_commit_parent_callback parent_cb, void *parent_payload,
const git_oid *current_id, bool validate)
git_commit_parent_callback parent_cb, void *parent_payload,
const git_oid *current_id, bool validate)
{
size_t i;
int error;
......@@ -152,8 +152,8 @@ static int git_commit__create_internal(
goto cleanup;
error = git_commit__create_buffer_internal(&buf, author, committer,
message_encoding, message, tree,
&parents);
message_encoding, message, tree,
&parents);
if (error < 0)
goto cleanup;
......@@ -582,7 +582,7 @@ const char *git_commit_body(git_commit *commit)
break;
if (*msg)
commit->body = git__strndup(msg, end - msg + 1);
commit->body = git__strndup(msg, end - msg + 1);
}
return commit->body;
......@@ -876,12 +876,15 @@ int git_commit_create_with_signature(
return -1;
}
field = signature_field ? signature_field : "gpgsig";
/* The header ends after the first LF */
header_end++;
git_buf_put(&commit, commit_content, header_end - commit_content);
format_header_field(&commit, field, signature);
if (signature != NULL) {
field = signature_field ? signature_field : "gpgsig";
format_header_field(&commit, field, signature);
}
git_buf_puts(&commit, header_end);
if (git_buf_oom(&commit))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment