2 * Builtin "git commit-commit"
4 * Copyright (c) 2014 Michael J Gruber <git@drmicha.warpmail.net>
6 * Based on git-verify-tag
11 #include "run-command.h"
13 #include "parse-options.h"
14 #include "gpg-interface.h"
16 static const char * const verify_commit_usage[] = {
17 N_("git verify-commit [-v | --verbose] <commit>..."),
21 static int run_gpg_verify(const unsigned char *sha1, const char *buf, unsigned long size, int verbose)
23 struct signature_check signature_check;
26 memset(&signature_check, 0, sizeof(signature_check));
28 ret = check_commit_signature(lookup_commit(sha1), &signature_check);
29 print_signature_buffer(&signature_check, verbose ? GPG_VERIFY_VERBOSE : 0);
31 signature_check_clear(&signature_check);
35 static int verify_commit(const char *name, int verbose)
37 enum object_type type;
38 unsigned char sha1[20];
43 if (get_sha1(name, sha1))
44 return error("commit '%s' not found.", name);
46 buf = read_sha1_file(sha1, &type, &size);
48 return error("%s: unable to read file.", name);
49 if (type != OBJ_COMMIT)
50 return error("%s: cannot verify a non-commit object of type %s.",
51 name, typename(type));
53 ret = run_gpg_verify(sha1, buf, size, verbose);
59 static int git_verify_commit_config(const char *var, const char *value, void *cb)
61 int status = git_gpg_config(var, value, cb);
64 return git_default_config(var, value, cb);
67 int cmd_verify_commit(int argc, const char **argv, const char *prefix)
69 int i = 1, verbose = 0, had_error = 0;
70 const struct option verify_commit_options[] = {
71 OPT__VERBOSE(&verbose, N_("print commit contents")),
75 git_config(git_verify_commit_config, NULL);
77 argc = parse_options(argc, argv, prefix, verify_commit_options,
78 verify_commit_usage, PARSE_OPT_KEEP_ARGV0);
80 usage_with_options(verify_commit_usage, verify_commit_options);
82 /* sometimes the program was terminated because this signal
83 * was received in the process of writing the gpg input: */
84 signal(SIGPIPE, SIG_IGN);
86 if (verify_commit(argv[i++], verbose))