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"
14 #include "gpg-interface.h"
16 static const char * const verify_tag_usage
[] = {
17 N_("git verify-tag [-v | --verbose] <tag>..."),
21 static int run_gpg_verify(const char *buf
, unsigned long size
, int verbose
)
23 struct signature_check sigc
;
26 memset(&sigc
, 0, sizeof(sigc
));
28 len
= parse_signature(buf
, size
);
30 write_in_full(1, buf
, len
);
33 return error("no signature found");
35 check_signature(buf
, len
, buf
+ len
, size
- len
, &sigc
);
36 fputs(sigc
.gpg_output
, stderr
);
38 signature_check_clear(&sigc
);
39 return sigc
.result
!= 'G' && sigc
.result
!= 'U';
42 static int verify_tag(const char *name
, int verbose
)
44 enum object_type type
;
45 unsigned char sha1
[20];
50 if (get_sha1(name
, sha1
))
51 return error("tag '%s' not found.", name
);
53 type
= sha1_object_info(sha1
, NULL
);
55 return error("%s: cannot verify a non-tag object of type %s.",
56 name
, typename(type
));
58 buf
= read_sha1_file(sha1
, &type
, &size
);
60 return error("%s: unable to read file.", name
);
62 ret
= run_gpg_verify(buf
, size
, verbose
);
68 static int git_verify_tag_config(const char *var
, const char *value
, void *cb
)
70 int status
= git_gpg_config(var
, value
, cb
);
73 return git_default_config(var
, value
, cb
);
76 int cmd_verify_tag(int argc
, const char **argv
, const char *prefix
)
78 int i
= 1, verbose
= 0, had_error
= 0;
79 const struct option verify_tag_options
[] = {
80 OPT__VERBOSE(&verbose
, N_("print tag contents")),
84 git_config(git_verify_tag_config
, NULL
);
86 argc
= parse_options(argc
, argv
, prefix
, verify_tag_options
,
87 verify_tag_usage
, PARSE_OPT_KEEP_ARGV0
);
89 usage_with_options(verify_tag_usage
, verify_tag_options
);
91 /* sometimes the program was terminated because this signal
92 * was received in the process of writing the gpg input: */
93 signal(SIGPIPE
, SIG_IGN
);
95 if (verify_tag(argv
[i
++], verbose
))