Git fork
at reftables-rust 73 lines 1.8 kB view raw
1/* 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 "builtin.h" 9#include "config.h" 10#include "environment.h" 11#include "gettext.h" 12#include "tag.h" 13#include "object-name.h" 14#include "parse-options.h" 15#include "gpg-interface.h" 16#include "ref-filter.h" 17 18static const char * const verify_tag_usage[] = { 19 N_("git verify-tag [-v | --verbose] [--format=<format>] [--raw] <tag>..."), 20 NULL 21}; 22 23int cmd_verify_tag(int argc, 24 const char **argv, 25 const char *prefix, 26 struct repository *repo) 27{ 28 int i = 1, verbose = 0, had_error = 0; 29 unsigned flags = 0; 30 struct ref_format format = REF_FORMAT_INIT; 31 const struct option verify_tag_options[] = { 32 OPT__VERBOSE(&verbose, N_("print tag contents")), 33 OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW), 34 OPT_STRING(0, "format", &format.format, N_("format"), N_("format to use for the output")), 35 OPT_END() 36 }; 37 38 repo_config(repo, git_default_config, NULL); 39 40 argc = parse_options(argc, argv, prefix, verify_tag_options, 41 verify_tag_usage, PARSE_OPT_KEEP_ARGV0); 42 if (argc <= i) 43 usage_with_options(verify_tag_usage, verify_tag_options); 44 45 if (verbose) 46 flags |= GPG_VERIFY_VERBOSE; 47 48 if (format.format) { 49 if (verify_ref_format(&format)) 50 usage_with_options(verify_tag_usage, 51 verify_tag_options); 52 flags |= GPG_VERIFY_OMIT_STATUS; 53 } 54 55 while (i < argc) { 56 struct object_id oid; 57 const char *name = argv[i++]; 58 59 if (repo_get_oid(repo, name, &oid)) { 60 had_error = !!error("tag '%s' not found.", name); 61 continue; 62 } 63 64 if (gpg_verify_tag(&oid, name, flags)) { 65 had_error = 1; 66 continue; 67 } 68 69 if (format.format) 70 pretty_print_ref(name, &oid, &format); 71 } 72 return had_error; 73}