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( ...@@ -480,7 +480,8 @@ GIT_EXTERN(int) git_commit_create_buffer(
* *
* @param out the resulting commit id * @param out the resulting commit id
* @param commit_content the content of the unsigned commit object * @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 * @param signature_field which header field should contain this
* signature. Leave `NULL` for the default of "gpgsig" * signature. Leave `NULL` for the default of "gpgsig"
* @return 0 or an error code * @return 0 or an error code
......
...@@ -876,12 +876,15 @@ int git_commit_create_with_signature( ...@@ -876,12 +876,15 @@ int git_commit_create_with_signature(
return -1; return -1;
} }
field = signature_field ? signature_field : "gpgsig";
/* The header ends after the first LF */ /* The header ends after the first LF */
header_end++; header_end++;
git_buf_put(&commit, commit_content, header_end - commit_content); git_buf_put(&commit, commit_content, header_end - commit_content);
if (signature != NULL) {
field = signature_field ? signature_field : "gpgsig";
format_header_field(&commit, field, signature); format_header_field(&commit, field, signature);
}
git_buf_puts(&commit, header_end); git_buf_puts(&commit, header_end);
if (git_buf_oom(&commit)) 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