aboutsummaryrefslogtreecommitdiffstats
path: root/commit.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-11-06 02:50:17 -0500
committerJunio C Hamano <gitster@pobox.com>2018-11-07 10:11:09 +0900
commitedc4d47d54cb1c0ec1550aa50bba86b23720a72f (patch)
tree446fbde148b7d06c7f628d8da7f81de4b217fe84 /commit.c
parentcae598d9980661a978e2df4fb338518f7bf09572 (diff)
downloadgit-edc4d47d54cb1c0ec1550aa50bba86b23720a72f.tar.gz
merge: extract verify_merge_signature() helper
The logic to implement "merge --verify-signatures" is inline in cmd_merge(), but this site misses some cases. Let's extract the logic into a function so we can call it from more places. We'll move it to commit.[ch], since one of the callers (git-pull) is outside our source file. This function isn't all that general (after all, its main function is to exit the program) but it's not worth trying to fix that. The heavy lifting is done by check_commit_signature(), and our purpose here is just sharing the die() logic. We'll mark it with a comment to make that clear. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/commit.c b/commit.c
index 449c1f4920..9abb9971a8 100644
--- a/commit.c
+++ b/commit.c
@@ -1379,7 +1379,33 @@ int check_commit_signature(const struct commit *commit, struct signature_check *
return ret;
}
+void verify_merge_signature(struct commit *commit, int verbosity)
+{
+ char hex[GIT_MAX_HEXSZ + 1];
+ struct signature_check signature_check;
+ memset(&signature_check, 0, sizeof(signature_check));
+
+ check_commit_signature(commit, &signature_check);
+
+ find_unique_abbrev_r(hex, &commit->object.oid, DEFAULT_ABBREV);
+ switch (signature_check.result) {
+ case 'G':
+ break;
+ case 'U':
+ die(_("Commit %s has an untrusted GPG signature, "
+ "allegedly by %s."), hex, signature_check.signer);
+ case 'B':
+ die(_("Commit %s has a bad GPG signature "
+ "allegedly by %s."), hex, signature_check.signer);
+ default: /* 'N' */
+ die(_("Commit %s does not have a GPG signature."), hex);
+ }
+ if (verbosity >= 0 && signature_check.result == 'G')
+ printf(_("Commit %s has a good GPG signature by %s\n"),
+ hex, signature_check.signer);
+ signature_check_clear(&signature_check);
+}
void append_merge_tag_headers(struct commit_list *parents,
struct commit_extra_header ***tail)