2 * Builtin "git verify-tag"
4 * Copyright (c) 2007 Carlos Rica <jasampler@gmail.com>
6 * Based on git-verify-tag.sh
11 #include "run-command.h"
13 #include "parse-options.h"
15 static const char * const verify_tag_usage[] = {
16 "git verify-tag [-v|--verbose] <tag>...",
20 static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
22 struct child_process gpg;
23 const char *args_gpg[] = {"gpg", "--verify", "FILE", "-", NULL};
28 fd = git_mkstemp(path, PATH_MAX, ".git_vtag_tmpXXXXXX");
30 return error("could not create temporary file '%s': %s",
31 path, strerror(errno));
32 if (write_in_full(fd, buf, size) < 0)
33 return error("failed writing temporary file '%s': %s",
34 path, strerror(errno));
37 /* find the length without signature */
38 len = parse_signature(buf, size);
40 write_in_full(1, buf, len);
42 memset(&gpg, 0, sizeof(gpg));
46 if (start_command(&gpg)) {
48 return error("could not run gpg.");
51 write_in_full(gpg.in, buf, len);
53 ret = finish_command(&gpg);
60 static int verify_tag(const char *name, int verbose)
62 enum object_type type;
63 unsigned char sha1[20];
68 if (get_sha1(name, sha1))
69 return error("tag '%s' not found.", name);
71 type = sha1_object_info(sha1, NULL);
73 return error("%s: cannot verify a non-tag object of type %s.",
74 name, typename(type));
76 buf = read_sha1_file(sha1, &type, &size);
78 return error("%s: unable to read file.", name);
80 ret = run_gpg_verify(buf, size, verbose);
86 int cmd_verify_tag(int argc, const char **argv, const char *prefix)
88 int i = 1, verbose = 0, had_error = 0;
89 const struct option verify_tag_options[] = {
90 OPT__VERBOSE(&verbose),
94 git_config(git_default_config, NULL);
96 argc = parse_options(argc, argv, prefix, verify_tag_options,
97 verify_tag_usage, PARSE_OPT_KEEP_ARGV0);
99 usage_with_options(verify_tag_usage, verify_tag_options);
101 /* sometimes the program was terminated because this signal
102 * was received in the process of writing the gpg input: */
103 signal(SIGPIPE, SIG_IGN);
105 if (verify_tag(argv[i++], verbose))