diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-08-09 09:01:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-09 09:01:56 +0200 |
| commit | b0692d6b3e818b9389295d7d33a0601143cc0c16 (patch) | |
| tree | 1ab0ec22115183c7215618a36b62f20e807281c2 /include | |
| parent | f627ba6c7f4b40d533cc127f408cbce8353697ed (diff) | |
| parent | 998f9c15fdca34bbfe6a3d92093afe9c7f886dcf (diff) | |
| download | libgit2-b0692d6b3e818b9389295d7d33a0601143cc0c16.tar.gz | |
Merge pull request #4913 from implausible/feature/signing-rebase-commits
Add sign capability to git_rebase_commit
Diffstat (limited to 'include')
| -rw-r--r-- | include/git2/commit.h | 24 | ||||
| -rw-r--r-- | include/git2/rebase.h | 18 |
2 files changed, 40 insertions, 2 deletions
diff --git a/include/git2/commit.h b/include/git2/commit.h index 7e0409cc7..e6c4656a9 100644 --- a/include/git2/commit.h +++ b/include/git2/commit.h @@ -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 @@ -501,6 +502,27 @@ GIT_EXTERN(int) git_commit_create_with_signature( */ GIT_EXTERN(int) git_commit_dup(git_commit **out, git_commit *source); +/** + * Commit signing callback. + * + * The callback will be called with the commit content, giving a user an + * opportunity to sign the commit content. The signature_field + * buf may be left empty to specify the default field "gpgsig". + * + * Signatures can take the form of any string, and can be created on an arbitrary + * header field. Signatures are most commonly used for verifying authorship of a + * commit using GPG or a similar cryptographically secure signing algorithm. + * See https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work for more + * details. + * + * When the callback: + * - returns GIT_PASSTHROUGH, no signature will be added to the commit. + * - returns < 0, commit creation will be aborted. + * - returns GIT_OK, the signature parameter is expected to be filled. + */ +typedef int (*git_commit_signing_cb)( + git_buf *signature, git_buf *signature_field, const char *commit_content, void *payload); + /** @} */ GIT_END_DECL #endif diff --git a/include/git2/rebase.h b/include/git2/rebase.h index 011d3e119..99a02fef9 100644 --- a/include/git2/rebase.h +++ b/include/git2/rebase.h @@ -13,6 +13,7 @@ #include "annotated_commit.h" #include "merge.h" #include "checkout.h" +#include "commit.h" /** * @file git2/rebase.h @@ -72,6 +73,21 @@ typedef struct { * `abort` to match git semantics. */ git_checkout_options checkout_options; + + /** + * If provided, this will be called with the commit content, allowing + * a signature to be added to the rebase commit. Can be skipped with + * GIT_PASSTHROUGH. If GIT_PASSTHROUGH is returned, a commit will be made + * without a signature. + * This field is only used when performing git_rebase_commit. + */ + git_commit_signing_cb signing_cb; + + /** + * This will be passed to each of the callbacks in this struct + * as the last parameter. + */ + void *payload; } git_rebase_options; /** @@ -118,7 +134,7 @@ typedef enum { #define GIT_REBASE_OPTIONS_VERSION 1 #define GIT_REBASE_OPTIONS_INIT \ { GIT_REBASE_OPTIONS_VERSION, 0, 0, NULL, GIT_MERGE_OPTIONS_INIT, \ - GIT_CHECKOUT_OPTIONS_INIT} + GIT_CHECKOUT_OPTIONS_INIT, NULL, NULL } /** Indicates that a rebase operation is not (yet) in progress. */ #define GIT_REBASE_NO_OPERATION SIZE_MAX |
