Merge branch 'ph/tag-force-no-warn-on-creation' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 3 Apr 2013 16:24:51 +0000 (09:24 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Apr 2013 16:24:51 +0000 (09:24 -0700)
"git tag -f <tag>" always said "Updated tag '<tag>'" even when
creating a new tag (i.e. not overwriting nor updating).

* ph/tag-force-no-warn-on-creation:
tag: --force does not have to warn when creating tags

1  2 
builtin/tag.c
diff --combined builtin/tag.c
index f8266888cca97f492dc5b52a992b1dc7cab2909e,d4824800b74849732e198c8b0a9ea4a57497d0b6..af3af3f64935c3f92ed3f85acd44ed2ca2a35b3f
@@@ -246,13 -246,19 +246,13 @@@ static int do_sign(struct strbuf *buffe
  }
  
  static const char tag_template[] =
 -      N_("\n"
 -      "#\n"
 -      "# Write a tag message\n"
 -      "# Lines starting with '#' will be ignored.\n"
 -      "#\n");
 +      N_("\nWrite a tag message\n"
 +      "Lines starting with '%c' will be ignored.\n");
  
  static const char tag_template_nocleanup[] =
 -      N_("\n"
 -      "#\n"
 -      "# Write a tag message\n"
 -      "# Lines starting with '#' will be kept; you may remove them"
 -      " yourself if you want to.\n"
 -      "#\n");
 +      N_("\nWrite a tag message\n"
 +      "Lines starting with '%c' will be kept; you may remove them"
 +      " yourself if you want to.\n");
  
  static int git_tag_config(const char *var, const char *value, void *cb)
  {
@@@ -340,18 -346,14 +340,18 @@@ static void create_tag(const unsigned c
                if (fd < 0)
                        die_errno(_("could not create file '%s'"), path);
  
 -              if (!is_null_sha1(prev))
 +              if (!is_null_sha1(prev)) {
                        write_tag_body(fd, prev);
 -              else if (opt->cleanup_mode == CLEANUP_ALL)
 -                      write_or_die(fd, _(tag_template),
 -                                      strlen(_(tag_template)));
 -              else
 -                      write_or_die(fd, _(tag_template_nocleanup),
 -                                      strlen(_(tag_template_nocleanup)));
 +              } else {
 +                      struct strbuf buf = STRBUF_INIT;
 +                      strbuf_addch(&buf, '\n');
 +                      if (opt->cleanup_mode == CLEANUP_ALL)
 +                              strbuf_commented_addf(&buf, _(tag_template), comment_line_char);
 +                      else
 +                              strbuf_commented_addf(&buf, _(tag_template_nocleanup), comment_line_char);
 +                      write_or_die(fd, buf.buf, buf.len);
 +                      strbuf_release(&buf);
 +              }
                close(fd);
  
                if (launch_editor(path, buf, NULL)) {
@@@ -582,7 -584,7 +582,7 @@@ int cmd_tag(int argc, const char **argv
                die(_("%s: cannot lock the ref"), ref.buf);
        if (write_ref_sha1(lock, object, NULL) < 0)
                die(_("%s: cannot update the ref"), ref.buf);
-       if (force && hashcmp(prev, object))
+       if (force && !is_null_sha1(prev) && hashcmp(prev, object))
                printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV));
  
        strbuf_release(&buf);