2 * Builtin "git commit-commit"
4 * Copyright (c) 2014 Michael J Gruber <git@drmicha.warpmail.net>
6 * Based on git-verify-tag
11 #include "object-name.h"
12 #include "repository.h"
14 #include "parse-options.h"
15 #include "gpg-interface.h"
17 static const char * const verify_commit_usage
[] = {
18 N_("git verify-commit [-v | --verbose] [--raw] <commit>..."),
22 static int run_gpg_verify(struct commit
*commit
, unsigned flags
)
24 struct signature_check signature_check
;
27 memset(&signature_check
, 0, sizeof(signature_check
));
29 ret
= check_commit_signature(commit
, &signature_check
);
30 print_signature_buffer(&signature_check
, flags
);
32 signature_check_clear(&signature_check
);
36 static int verify_commit(const char *name
, unsigned flags
)
41 if (repo_get_oid(the_repository
, name
, &oid
))
42 return error("commit '%s' not found.", name
);
44 obj
= parse_object(the_repository
, &oid
);
46 return error("%s: unable to read file.", name
);
47 if (obj
->type
!= OBJ_COMMIT
)
48 return error("%s: cannot verify a non-commit object of type %s.",
49 name
, type_name(obj
->type
));
51 return run_gpg_verify((struct commit
*)obj
, flags
);
54 int cmd_verify_commit(int argc
, const char **argv
, const char *prefix
)
56 int i
= 1, verbose
= 0, had_error
= 0;
58 const struct option verify_commit_options
[] = {
59 OPT__VERBOSE(&verbose
, N_("print commit contents")),
60 OPT_BIT(0, "raw", &flags
, N_("print raw gpg status output"), GPG_VERIFY_RAW
),
64 git_config(git_default_config
, NULL
);
66 argc
= parse_options(argc
, argv
, prefix
, verify_commit_options
,
67 verify_commit_usage
, PARSE_OPT_KEEP_ARGV0
);
69 usage_with_options(verify_commit_usage
, verify_commit_options
);
72 flags
|= GPG_VERIFY_VERBOSE
;
74 /* sometimes the program was terminated because this signal
75 * was received in the process of writing the gpg input: */
76 signal(SIGPIPE
, SIG_IGN
);
78 if (verify_commit(argv
[i
++], flags
))