verify-tag.c 1.8 KB

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