2014-06-23 07:05:49 +00:00
|
|
|
/*
|
|
|
|
* Builtin "git commit-commit"
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Michael J Gruber <git@drmicha.warpmail.net>
|
|
|
|
*
|
|
|
|
* Based on git-verify-tag
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
2017-06-14 18:07:36 +00:00
|
|
|
#include "config.h"
|
2014-06-23 07:05:49 +00:00
|
|
|
#include "builtin.h"
|
2023-03-21 06:25:54 +00:00
|
|
|
#include "gettext.h"
|
2023-04-11 07:41:49 +00:00
|
|
|
#include "object-name.h"
|
2018-05-15 23:42:15 +00:00
|
|
|
#include "object-store.h"
|
2018-06-29 01:21:59 +00:00
|
|
|
#include "repository.h"
|
2014-06-23 07:05:49 +00:00
|
|
|
#include "commit.h"
|
|
|
|
#include "run-command.h"
|
|
|
|
#include "parse-options.h"
|
|
|
|
#include "gpg-interface.h"
|
|
|
|
|
|
|
|
static const char * const verify_commit_usage[] = {
|
2022-10-13 15:39:13 +00:00
|
|
|
N_("git verify-commit [-v | --verbose] [--raw] <commit>..."),
|
2014-06-23 07:05:49 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2019-05-09 21:32:29 +00:00
|
|
|
static int run_gpg_verify(struct commit *commit, unsigned flags)
|
2014-06-23 07:05:49 +00:00
|
|
|
{
|
|
|
|
struct signature_check signature_check;
|
2015-06-21 23:14:40 +00:00
|
|
|
int ret;
|
2014-06-23 07:05:49 +00:00
|
|
|
|
|
|
|
memset(&signature_check, 0, sizeof(signature_check));
|
|
|
|
|
2019-05-09 21:32:29 +00:00
|
|
|
ret = check_commit_signature(commit, &signature_check);
|
2015-06-21 23:14:42 +00:00
|
|
|
print_signature_buffer(&signature_check, flags);
|
2014-06-23 07:05:49 +00:00
|
|
|
|
|
|
|
signature_check_clear(&signature_check);
|
2015-06-21 23:14:40 +00:00
|
|
|
return ret;
|
2014-06-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
|
2015-06-21 23:14:42 +00:00
|
|
|
static int verify_commit(const char *name, unsigned flags)
|
2014-06-23 07:05:49 +00:00
|
|
|
{
|
2017-05-06 22:10:01 +00:00
|
|
|
struct object_id oid;
|
2019-05-09 21:32:29 +00:00
|
|
|
struct object *obj;
|
2014-06-23 07:05:49 +00:00
|
|
|
|
2023-03-28 13:58:46 +00:00
|
|
|
if (repo_get_oid(the_repository, name, &oid))
|
2014-06-23 07:05:49 +00:00
|
|
|
return error("commit '%s' not found.", name);
|
|
|
|
|
2019-05-09 21:32:29 +00:00
|
|
|
obj = parse_object(the_repository, &oid);
|
|
|
|
if (!obj)
|
2014-06-23 07:05:49 +00:00
|
|
|
return error("%s: unable to read file.", name);
|
2019-05-09 21:32:29 +00:00
|
|
|
if (obj->type != OBJ_COMMIT)
|
2014-06-23 07:05:49 +00:00
|
|
|
return error("%s: cannot verify a non-commit object of type %s.",
|
2019-05-09 21:32:29 +00:00
|
|
|
name, type_name(obj->type));
|
2014-06-23 07:05:49 +00:00
|
|
|
|
2019-05-09 21:32:29 +00:00
|
|
|
return run_gpg_verify((struct commit *)obj, flags);
|
2014-06-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_verify_commit(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int i = 1, verbose = 0, had_error = 0;
|
2015-06-21 23:14:42 +00:00
|
|
|
unsigned flags = 0;
|
2014-06-23 07:05:49 +00:00
|
|
|
const struct option verify_commit_options[] = {
|
|
|
|
OPT__VERBOSE(&verbose, N_("print commit contents")),
|
2015-06-21 23:14:42 +00:00
|
|
|
OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW),
|
2014-06-23 07:05:49 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2023-02-26 22:40:46 +00:00
|
|
|
git_config(git_default_config, NULL);
|
2014-06-23 07:05:49 +00:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, verify_commit_options,
|
|
|
|
verify_commit_usage, PARSE_OPT_KEEP_ARGV0);
|
|
|
|
if (argc <= i)
|
|
|
|
usage_with_options(verify_commit_usage, verify_commit_options);
|
|
|
|
|
2015-06-21 23:14:42 +00:00
|
|
|
if (verbose)
|
|
|
|
flags |= GPG_VERIFY_VERBOSE;
|
|
|
|
|
2014-06-23 07:05:49 +00:00
|
|
|
/* sometimes the program was terminated because this signal
|
|
|
|
* was received in the process of writing the gpg input: */
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
while (i < argc)
|
2015-06-21 23:14:42 +00:00
|
|
|
if (verify_commit(argv[i++], flags))
|
2014-06-23 07:05:49 +00:00
|
|
|
had_error = 1;
|
|
|
|
return had_error;
|
|
|
|
}
|