Merge branch 'nm/tag-edit'
authorJunio C Hamano <gitster@pobox.com>
Tue, 6 Mar 2018 22:53:59 +0000 (14:53 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Mar 2018 22:53:59 +0000 (14:53 -0800)
"git tag" learned an explicit "--edit" option that allows the
message given via "-m" and "-F" to be further edited.

* nm/tag-edit:
tag: add --edit option

1  2 
builtin/tag.c
diff --combined builtin/tag.c
index 8885e21ddc81e4d2686aaeb6fe4c1bbffc916ec1,ce5cac3dd23f5403fffd0e78333809a60b4e428e..26f8d5136528bb5e92e1f3b78bde7a37f4188f1e
@@@ -187,13 -187,14 +187,14 @@@ static int build_tag_object(struct strb
  {
        if (sign && do_sign(buf) < 0)
                return error(_("unable to sign the tag"));
 -      if (write_sha1_file(buf->buf, buf->len, tag_type, result->hash) < 0)
 +      if (write_object_file(buf->buf, buf->len, tag_type, result) < 0)
                return error(_("unable to write tag file"));
        return 0;
  }
  
  struct create_tag_options {
        unsigned int message_given:1;
+       unsigned int use_editor:1;
        unsigned int sign;
        enum {
                CLEANUP_NONE,
@@@ -224,7 -225,7 +225,7 @@@ static void create_tag(const struct obj
                    tag,
                    git_committer_info(IDENT_STRICT));
  
-       if (!opt->message_given) {
+       if (!opt->message_given || opt->use_editor) {
                int fd;
  
                /* write the template message before editing: */
                if (fd < 0)
                        die_errno(_("could not create file '%s'"), path);
  
-               if (!is_null_oid(prev)) {
+               if (opt->message_given) {
+                       write_or_die(fd, buf->buf, buf->len);
+                       strbuf_reset(buf);
+               } else if (!is_null_oid(prev)) {
                        write_tag_body(fd, prev);
                } else {
                        struct strbuf buf = STRBUF_INIT;
@@@ -372,6 -376,7 +376,7 @@@ int cmd_tag(int argc, const char **argv
        static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
        struct ref_format format = REF_FORMAT_INIT;
        int icase = 0;
+       int edit_flag = 0;
        struct option options[] = {
                OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
                { OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
                OPT_CALLBACK('m', "message", &msg, N_("message"),
                             N_("tag message"), parse_msg_arg),
                OPT_FILENAME('F', "file", &msgfile, N_("read message from file")),
+               OPT_BOOL('e', "edit", &edit_flag, N_("force edit of tag message")),
                OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")),
                OPT_STRING(0, "cleanup", &cleanup_arg, N_("mode"),
                        N_("how to strip spaces and #comments from message")),
                die(_("tag '%s' already exists"), tag);
  
        opt.message_given = msg.given || msgfile;
+       opt.use_editor = edit_flag;
  
        if (!cleanup_arg || !strcmp(cleanup_arg, "strip"))
                opt.cleanup_mode = CLEANUP_ALL;