{"thread":{"id":"47781","subject":"[PATCHv4] tag: add --edit option","startedAt":"2018-02-07T16:56:02Z","lastAt":"2018-02-08T08:22:26Z","messageCount":2,"participants":["Nicolas Morey-Chaisemartin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"338634","messageId":"09e24322-7eee-6c83-1db0-318815155fac@suse.com","threadId":"47781","inReplyTo":null,"subject":"[PATCHv4] tag: add --edit option","fromName":"Nicolas Morey-Chaisemartin","fromEmail":"nmoreychaisemartin@suse.com","sentAt":"2018-02-07T16:55:45Z","receivedAt":"2018-02-07T16:56:02Z","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\nFixes since v3 ( https://public-inbox.org/git/88e7c122-599f-4ab1-6d65-c75f7a3ae8bb@suse.com/ ):\n * Replace tab by space in t/t7004-tag.sh\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..0630f2dee24b 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 git 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 git 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":"338691","messageId":"7e44c238-6264-e9a5-b159-7cf2905c6a13@suse.com","threadId":"47781","inReplyTo":"09e24322-7eee-6c83-1db0-318815155fac@suse.com","subject":"Re: [PATCHv4] tag: add --edit option","fromName":"Nicolas Morey-Chaisemartin","fromEmail":"nmoreychaisemartin@suse.com","sentAt":"2018-02-08T08:22:20Z","receivedAt":"2018-02-08T08:22:26Z","isPatch":false,"sender":{"key":"devel-git@morey-chaisemartin.com","avatar":"https://avatars.githubusercontent.com/u/108326?v=4"},"body":"Please ignore !\n\nv3 with the nits fixed was picked by Junio\n\nLe 07/02/2018 à 17:55, Nicolas Morey-Chaisemartin a écrit :\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>\n> Fixes since v3 ( https://public-inbox.org/git/88e7c122-599f-4ab1-6d65-c75f7a3ae8bb@suse.com/ ):\n>  * Replace tab by space in t/t7004-tag.sh\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>\n> diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt\n> index 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\n> diff --git a/builtin/tag.c b/builtin/tag.c\n> index 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;\n> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh\n> index a9af2de9960b..0630f2dee24b 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 git 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 git 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\n"}]}