Merge branch 'dl/warn-tagging-a-tag'
authorJunio C Hamano <gitster@pobox.com>
Wed, 8 May 2019 15:37:22 +0000 (00:37 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 May 2019 15:37:22 +0000 (00:37 +0900)
"git tag" learned to give an advice suggesting it might be a
mistake when creating an annotated or signed tag that points at
another tag.

* dl/warn-tagging-a-tag:
tag: advise on nested tags
tag: fix formatting

1  2 
builtin/tag.c
diff --combined builtin/tag.c
index ad97595fbfaa25c8ec44efec8ce5f946cf7de184,32948fade05c75d7f923ca0b17e93ef0ef714e1a..8399a0ed5414321f9893f94d93dab6788f2175af
  #include "ref-filter.h"
  
  static const char * const git_tag_usage[] = {
-       N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] <tagname> [<head>]"),
+       N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>]\n"
+               "\t\t<tagname> [<head>]"),
        N_("git tag -d <tagname>..."),
-       N_("git tag -l [-n[<num>]] [--contains <commit>] [--no-contains <commit>] [--points-at <object>]"
-               "\n\t\t[--format=<format>] [--[no-]merged [<commit>]] [<pattern>...]"),
+       N_("git tag -l [-n[<num>]] [--contains <commit>] [--no-contains <commit>] [--points-at <object>]\n"
+               "\t\t[--format=<format>] [--[no-]merged [<commit>]] [<pattern>...]"),
        N_("git tag -v [--format=<format>] <tagname>..."),
        NULL
  };
@@@ -205,7 -206,14 +206,14 @@@ struct create_tag_options 
        } cleanup_mode;
  };
  
- static void create_tag(const struct object_id *object, const char *tag,
+ static const char message_advice_nested_tag[] =
+       N_("You have created a nested tag. The object referred to by your new is\n"
+          "already a tag. If you meant to tag the object that it points to, use:\n"
+          "\n"
+          "\tgit tag -f %s %s^{}");
+ static void create_tag(const struct object_id *object, const char *object_ref,
+                      const char *tag,
                       struct strbuf *buf, struct create_tag_options *opt,
                       struct object_id *prev, struct object_id *result)
  {
  
        type = oid_object_info(the_repository, object, NULL);
        if (type <= OBJ_NONE)
-           die(_("bad object type."));
+               die(_("bad object type."));
+       if (type == OBJ_TAG && advice_nested_tag)
+               advise(_(message_advice_nested_tag), tag, object_ref);
  
        strbuf_addf(&header,
                    "object %s\n"
@@@ -412,7 -423,8 +423,7 @@@ int cmd_tag(int argc, const char **argv
                OPT_WITHOUT(&filter.no_commit, N_("print only tags that don't contain the commit")),
                OPT_MERGED(&filter, N_("print only tags that are merged")),
                OPT_NO_MERGED(&filter, N_("print only tags that are not merged")),
 -              OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
 -                           N_("field name to sort on"), &parse_opt_ref_sorting),
 +              OPT_REF_SORT(sorting_tail),
                {
                        OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"),
                        N_("print only tags of the object"), PARSE_OPT_LASTARG_DEFAULT,
        if (create_tag_object) {
                if (force_sign_annotate && !annotate)
                        opt.sign = 1;
-               create_tag(&object, tag, &buf, &opt, &prev, &object);
+               create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object);
        }
  
        transaction = ref_transaction_begin(&err);