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-store.h"
12 #include "repository.h"
14 #include "run-command.h"
15 #include "parse-options.h"
16 #include "gpg-interface.h"
18 static const char * const verify_commit_usage
[] = {
19 N_("git verify-commit [-v | --verbose] <commit>..."),
23 static int run_gpg_verify(struct commit
*commit
, unsigned flags
)
25 struct signature_check signature_check
;
28 memset(&signature_check
, 0, sizeof(signature_check
));
30 ret
= check_commit_signature(commit
, &signature_check
);
31 print_signature_buffer(&signature_check
, flags
);
33 signature_check_clear(&signature_check
);
37 static int verify_commit(const char *name
, unsigned flags
)
42 if (get_oid(name
, &oid
))
43 return error("commit '%s' not found.", name
);
45 obj
= parse_object(the_repository
, &oid
);
47 return error("%s: unable to read file.", name
);
48 if (obj
->type
!= OBJ_COMMIT
)
49 return error("%s: cannot verify a non-commit object of type %s.",
50 name
, type_name(obj
->type
));
52 return run_gpg_verify((struct commit
*)obj
, flags
);
55 static int git_verify_commit_config(const char *var
, const char *value
, void *cb
)
57 int status
= git_gpg_config(var
, value
, cb
);
60 return git_default_config(var
, value
, cb
);
63 int cmd_verify_commit(int argc
, const char **argv
, const char *prefix
)
65 int i
= 1, verbose
= 0, had_error
= 0;
67 const struct option verify_commit_options
[] = {
68 OPT__VERBOSE(&verbose
, N_("print commit contents")),
69 OPT_BIT(0, "raw", &flags
, N_("print raw gpg status output"), GPG_VERIFY_RAW
),
73 git_config(git_verify_commit_config
, NULL
);
75 argc
= parse_options(argc
, argv
, prefix
, verify_commit_options
,
76 verify_commit_usage
, PARSE_OPT_KEEP_ARGV0
);
78 usage_with_options(verify_commit_usage
, verify_commit_options
);
81 flags
|= GPG_VERIFY_VERBOSE
;
83 /* sometimes the program was terminated because this signal
84 * was received in the process of writing the gpg input: */
85 signal(SIGPIPE
, SIG_IGN
);
87 if (verify_commit(argv
[i
++], flags
))