{"thread":{"id":"47767","subject":"[PATCHv3] tag: add --edit option","startedAt":"2018-02-06T08:36:32Z","lastAt":"2018-02-07T20:47:12Z","messageCount":3,"participants":["Nicolas Morey-Chaisemartin","Eric Sunshine","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"338486","messageId":"88e7c122-599f-4ab1-6d65-c75f7a3ae8bb@suse.com","threadId":"47767","inReplyTo":null,"subject":"[PATCHv3] tag: add --edit option","fromName":"Nicolas Morey-Chaisemartin","fromEmail":"nmoreychaisemartin@suse.com","sentAt":"2018-02-06T08:36:24Z","receivedAt":"2018-02-06T08:36:32Z","isPatch":false,"sender":{"key":"devel-git@morey-chaisemartin.com","avatar":"https://avatars.githubusercontent.com/u/108326?v=4"},"body":"Add a --edit option whichs allows modifying the messages provided by -m or -F,\nthe same way git commit --edit does.\n\nSigned-off-by: Nicolas Morey-Chaisemartin <NMoreyChaisemartin@suse.com>\n---\n\nChanges since v2 ( https://public-inbox.org/git/e99947cf-93ba-9376-f059-7f6a369d3ad5@suse.com ):\n * Add [-e] to git tag summary\n\n\n Documentation/git-tag.txt |  8 +++++++-\n builtin/tag.c             | 11 +++++++++--\n t/t7004-tag.sh            | 30 ++++++++++++++++++++++++++++++\n 3 files changed, 46 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt\nindex 956fc019f984..1d17101bac39 100644\n--- a/Documentation/git-tag.txt\n+++ b/Documentation/git-tag.txt\n@@ -9,7 +9,7 @@ git-tag - Create, list, delete or verify a tag object signed with GPG\n SYNOPSIS\n --------\n [verse]\n-'git tag' [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>]\n+'git tag' [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>] [-e]\n \t<tagname> [<commit> | <object>]\n 'git tag' -d <tagname>...\n 'git tag' [-n[<num>]] -l [--contains <commit>] [--no-contains <commit>]\n@@ -167,6 +167,12 @@ This option is only applicable when listing tags without annotation lines.\n \tImplies `-a` if none of `-a`, `-s`, or `-u <keyid>`\n \tis given.\n \n+-e::\n+--edit::\n+\tThe message taken from file with `-F` and command line with\n+\t`-m` are usually used as the tag message unmodified.\n+\tThis option lets you further edit the message taken from these sources.\n+\n --cleanup=<mode>::\n \tThis option sets how the tag message is cleaned up.\n \tThe  '<mode>' can be one of 'verbatim', 'whitespace' and 'strip'.  The\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex a7e6a5b0f234..ce5cac3dd23f 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -194,6 +194,7 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu\n \n struct create_tag_options {\n \tunsigned int message_given:1;\n+\tunsigned int use_editor:1;\n \tunsigned int sign;\n \tenum {\n \t\tCLEANUP_NONE,\n@@ -224,7 +225,7 @@ static void create_tag(const struct object_id *object, const char *tag,\n \t\t    tag,\n \t\t    git_committer_info(IDENT_STRICT));\n \n-\tif (!opt->message_given) {\n+\tif (!opt->message_given || opt->use_editor) {\n \t\tint fd;\n \n \t\t/* write the template message before editing: */\n@@ -233,7 +234,10 @@ static void create_tag(const struct object_id *object, const char *tag,\n \t\tif (fd < 0)\n \t\t\tdie_errno(_(\"could not create file '%s'\"), path);\n \n-\t\tif (!is_null_oid(prev)) {\n+\t\tif (opt->message_given) {\n+\t\t\twrite_or_die(fd, buf->buf, buf->len);\n+\t\t\tstrbuf_reset(buf);\n+\t\t} else if (!is_null_oid(prev)) {\n \t\t\twrite_tag_body(fd, prev);\n \t\t} else {\n \t\t\tstruct strbuf buf = STRBUF_INIT;\n@@ -372,6 +376,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \tstatic struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;\n \tstruct ref_format format = REF_FORMAT_INIT;\n \tint icase = 0;\n+\tint edit_flag = 0;\n \tstruct option options[] = {\n \t\tOPT_CMDMODE('l', \"list\", &cmdmode, N_(\"list tag names\"), 'l'),\n \t\t{ OPTION_INTEGER, 'n', NULL, &filter.lines, N_(\"n\"),\n@@ -386,6 +391,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\tOPT_CALLBACK('m', \"message\", &msg, N_(\"message\"),\n \t\t\t     N_(\"tag message\"), parse_msg_arg),\n \t\tOPT_FILENAME('F', \"file\", &msgfile, N_(\"read message from file\")),\n+\t\tOPT_BOOL('e', \"edit\", &edit_flag, N_(\"force edit of tag message\")),\n \t\tOPT_BOOL('s', \"sign\", &opt.sign, N_(\"annotated and GPG-signed tag\")),\n \t\tOPT_STRING(0, \"cleanup\", &cleanup_arg, N_(\"mode\"),\n \t\t\tN_(\"how to strip spaces and #comments from message\")),\n@@ -524,6 +530,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\tdie(_(\"tag '%s' already exists\"), tag);\n \n \topt.message_given = msg.given || msgfile;\n+\topt.use_editor = edit_flag;\n \n \tif (!cleanup_arg || !strcmp(cleanup_arg, \"strip\"))\n \t\topt.cleanup_mode = CLEANUP_ALL;\ndiff --git a/t/t7004-tag.sh b/t/t7004-tag.sh\nindex a9af2de9960b..063996ddc05c 100755\n--- a/t/t7004-tag.sh\n+++ b/t/t7004-tag.sh\n@@ -452,6 +452,21 @@ test_expect_success \\\n \ttest_cmp expect actual\n '\n \n+get_tag_header annotated-tag-edit $commit commit $time >expect\n+echo \"An edited message\" >>expect\n+test_expect_success 'set up editor' '\n+\twrite_script fakeeditor <<-\\EOF\n+\tsed -e \"s/A message/An edited message/g\" <\"$1\" >\"$1-\"\n+\tmv \"$1-\" \"$1\"\n+\tEOF\n+'\n+test_expect_success \\\n+\t'creating an annotated tag with -m message --edit should succeed' '\n+\tEDITOR=./fakeeditor\tgit tag -m \"A message\" --edit annotated-tag-edit &&\n+\tget_tag_msg annotated-tag-edit >actual &&\n+\ttest_cmp expect actual\n+'\n+\n cat >msgfile <<EOF\n Another message\n in a file.\n@@ -465,6 +480,21 @@ test_expect_success \\\n \ttest_cmp expect actual\n '\n \n+get_tag_header file-annotated-tag-edit $commit commit $time >expect\n+sed -e \"s/Another message/Another edited message/g\" msgfile >>expect\n+test_expect_success 'set up editor' '\n+\twrite_script fakeeditor <<-\\EOF\n+\tsed -e \"s/Another message/Another edited message/g\" <\"$1\" >\"$1-\"\n+\tmv \"$1-\" \"$1\"\n+\tEOF\n+'\n+test_expect_success \\\n+\t'creating an annotated tag with -F messagefile --edit should succeed' '\n+\tEDITOR=./fakeeditor\tgit tag -F msgfile --edit file-annotated-tag-edit &&\n+\tget_tag_msg file-annotated-tag-edit >actual &&\n+\ttest_cmp expect actual\n+'\n+\n cat >inputmsg <<EOF\n A message from the\n standard input\n-- \n2.16.1.73.g3702124ca069\n\n"},{"id":"338601","messageId":"CAPig+cQ=Uvp5k7NprzqU1Cfi1b0jj5T63Nxzqg+O5ucinD9fmQ@mail.gmail.com","threadId":"47767","inReplyTo":"88e7c122-599f-4ab1-6d65-c75f7a3ae8bb@suse.com","subject":"Re: [PATCHv3] tag: add --edit option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-07T10:00:45Z","receivedAt":"2018-02-07T10:00:57Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Feb 6, 2018 at 3:36 AM, Nicolas Morey-Chaisemartin\n<nmoreychaisemartin@suse.com> wrote:\n> Add a --edit option whichs allows modifying the messages provided by -m or -F,\n> the same way git commit --edit does.\n>\n> Signed-off-by: Nicolas Morey-Chaisemartin <NMoreyChaisemartin@suse.com>\n> ---\n> Changes since v2 ( https://public-inbox.org/git/e99947cf-93ba-9376-f059-7f6a369d3ad5@suse.com ):\n>  * Add [-e] to git tag summary\n\nThanks, I think this addresses all my comments from previous rounds.\nJust a couple minor style issues below...\n\n> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh\n> @@ -452,6 +452,21 @@ test_expect_success \\\n> +> +test_expect_success \\\n> +       'creating an annotated tag with -m message --edit should succeed' '\n> +       EDITOR=./fakeeditor     git tag -m \"A message\" --edit annotated-tag-edit &&\n\nWhitespace between 'fakeeditor' and 'git' is a tab but should be a space.\n\n> +       get_tag_msg annotated-tag-edit >actual &&\n> +       test_cmp expect actual\n> +'\n> @@ -465,6 +480,21 @@ test_expect_success \\\n> +test_expect_success \\\n> +       'creating an annotated tag with -F messagefile --edit should succeed' '\n> +       EDITOR=./fakeeditor     git tag -F msgfile --edit file-annotated-tag-edit &&\n\nDitto.\n\n> +       get_tag_msg file-annotated-tag-edit >actual &&\n> +       test_cmp expect actual\n> +'\n"},{"id":"338668","messageId":"xmqq7ero7cjd.fsf@gitster-ct.c.googlers.com","threadId":"47767","inReplyTo":"CAPig+cQ=Uvp5k7NprzqU1Cfi1b0jj5T63Nxzqg+O5ucinD9fmQ@mail.gmail.com","subject":"Re: [PATCHv3] tag: add --edit option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-07T20:47:02Z","receivedAt":"2018-02-07T20:47:12Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Tue, Feb 6, 2018 at 3:36 AM, Nicolas Morey-Chaisemartin\n> <nmoreychaisemartin@suse.com> wrote:\n>> Add a --edit option whichs allows modifying the messages provided by -m or -F,\n>> the same way git commit --edit does.\n>>\n>> Signed-off-by: Nicolas Morey-Chaisemartin <NMoreyChaisemartin@suse.com>\n>> ---\n>> Changes since v2 ( https://public-inbox.org/git/e99947cf-93ba-9376-f059-7f6a369d3ad5@suse.com ):\n>>  * Add [-e] to git tag summary\n>\n> Thanks, I think this addresses all my comments from previous rounds.\n> Just a couple minor style issues below...\n>\n>> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh\n>> @@ -452,6 +452,21 @@ test_expect_success \\\n>> +> +test_expect_success \\\n>> +       'creating an annotated tag with -m message --edit should succeed' '\n>> +       EDITOR=./fakeeditor     git tag -m \"A message\" --edit annotated-tag-edit &&\n>\n> Whitespace between 'fakeeditor' and 'git' is a tab but should be a space.\n>\n>> +       get_tag_msg annotated-tag-edit >actual &&\n>> +       test_cmp expect actual\n>> +'\n>> @@ -465,6 +480,21 @@ test_expect_success \\\n>> +test_expect_success \\\n>> +       'creating an annotated tag with -F messagefile --edit should succeed' '\n>> +       EDITOR=./fakeeditor     git tag -F msgfile --edit file-annotated-tag-edit &&\n>\n> Ditto.\n>\n>> +       get_tag_msg file-annotated-tag-edit >actual &&\n>> +       test_cmp expect actual\n>> +'\n\nAlso, GIT_EDITOR takes precedence over EDITOR, so these two new\ntests should use it instead, just like other existing tests do.\n\nWill try to amend locally before queuing, so unless I botch that (or\nothers find other things to tweak), no need to re-send.\n\nThanks, both.\n"}]}