blob: 6fa04b751ac1d6ae18b8a42e700e2cefa6427a41 [file] [log] [blame]
Carlos Rica2ae68fc2007-07-27 06:07:34 +02001/*
2 * Builtin "git verify-tag"
3 *
4 * Copyright (c) 2007 Carlos Rica <jasampler@gmail.com>
5 *
6 * Based on git-verify-tag.sh
7 */
8#include "cache.h"
Brandon Williamsb2141fc2017-06-14 11:07:36 -07009#include "config.h"
Carlos Rica2ae68fc2007-07-27 06:07:34 +020010#include "builtin.h"
11#include "tag.h"
12#include "run-command.h"
13#include <signal.h>
Stephen Boyd4855b2a2009-07-07 22:15:39 -070014#include "parse-options.h"
Junio C Hamano2f47eae2011-09-07 21:19:47 -070015#include "gpg-interface.h"
Santiago Torresff3c8c82017-01-17 18:37:20 -050016#include "ref-filter.h"
Carlos Rica2ae68fc2007-07-27 06:07:34 +020017
Stephen Boyd4855b2a2009-07-07 22:15:39 -070018static const char * const verify_tag_usage[] = {
Santiago Torresff3c8c82017-01-17 18:37:20 -050019 N_("git verify-tag [-v | --verbose] [--format=<format>] <tag>..."),
Stephen Boyd4855b2a2009-07-07 22:15:39 -070020 NULL
21};
Carlos Rica2ae68fc2007-07-27 06:07:34 +020022
Alex Zepedaa2c25062012-03-08 12:07:20 -080023static int git_verify_tag_config(const char *var, const char *value, void *cb)
24{
25 int status = git_gpg_config(var, value, cb);
26 if (status)
27 return status;
28 return git_default_config(var, value, cb);
29}
30
Carlos Rica2ae68fc2007-07-27 06:07:34 +020031int cmd_verify_tag(int argc, const char **argv, const char *prefix)
32{
33 int i = 1, verbose = 0, had_error = 0;
brian m. carlsone18443e2015-06-21 23:14:43 +000034 unsigned flags = 0;
Jeff King4a68e362017-07-13 11:01:18 -040035 struct ref_format format = REF_FORMAT_INIT;
Stephen Boyd4855b2a2009-07-07 22:15:39 -070036 const struct option verify_tag_options[] = {
Nguyễn Thái Ngọc Duyf6008eb2012-08-20 19:32:52 +070037 OPT__VERBOSE(&verbose, N_("print tag contents")),
brian m. carlsone18443e2015-06-21 23:14:43 +000038 OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW),
Jeff King4a68e362017-07-13 11:01:18 -040039 OPT_STRING(0, "format", &format.format, N_("format"), N_("format to use for the output")),
Stephen Boyd4855b2a2009-07-07 22:15:39 -070040 OPT_END()
41 };
Carlos Rica2ae68fc2007-07-27 06:07:34 +020042
Alex Zepedaa2c25062012-03-08 12:07:20 -080043 git_config(git_verify_tag_config, NULL);
Carlos Rica2ae68fc2007-07-27 06:07:34 +020044
Stephen Boyd4855b2a2009-07-07 22:15:39 -070045 argc = parse_options(argc, argv, prefix, verify_tag_options,
46 verify_tag_usage, PARSE_OPT_KEEP_ARGV0);
Olivier Marind2761892008-07-28 12:48:44 +020047 if (argc <= i)
Stephen Boyd4855b2a2009-07-07 22:15:39 -070048 usage_with_options(verify_tag_usage, verify_tag_options);
Olivier Marind2761892008-07-28 12:48:44 +020049
brian m. carlsone18443e2015-06-21 23:14:43 +000050 if (verbose)
51 flags |= GPG_VERIFY_VERBOSE;
52
Jeff King4a68e362017-07-13 11:01:18 -040053 if (format.format) {
54 if (verify_ref_format(&format))
Jeff King2eda0102017-07-13 10:56:10 -040055 usage_with_options(verify_tag_usage,
56 verify_tag_options);
Santiago Torresff3c8c82017-01-17 18:37:20 -050057 flags |= GPG_VERIFY_OMIT_STATUS;
58 }
59
Santiago Torres78ccd442016-04-19 13:47:19 -040060 while (i < argc) {
Stefan Beller84571762017-07-12 17:44:15 -070061 struct object_id oid;
Santiago Torres78ccd442016-04-19 13:47:19 -040062 const char *name = argv[i++];
Stefan Beller84571762017-07-12 17:44:15 -070063
64 if (get_oid(name, &oid)) {
Santiago Torres78ccd442016-04-19 13:47:19 -040065 had_error = !!error("tag '%s' not found.", name);
Santiago Torresff3c8c82017-01-17 18:37:20 -050066 continue;
67 }
68
Stefan Beller84571762017-07-12 17:44:15 -070069 if (gpg_verify_tag(&oid, name, flags)) {
Carlos Rica2ae68fc2007-07-27 06:07:34 +020070 had_error = 1;
Santiago Torresff3c8c82017-01-17 18:37:20 -050071 continue;
72 }
73
Jeff King4a68e362017-07-13 11:01:18 -040074 if (format.format)
Jeff King53df97a2018-04-06 14:58:32 -040075 pretty_print_ref(name, &oid, &format);
Santiago Torres78ccd442016-04-19 13:47:19 -040076 }
Carlos Rica2ae68fc2007-07-27 06:07:34 +020077 return had_error;
78}