{"thread":{"id":"33932","subject":"Commit with an empty message broken since v1.8.2.1","startedAt":"2013-05-25T19:12:06Z","lastAt":"2013-05-27T17:57:00Z","messageCount":7,"participants":["Mislav Marohnić","René Scharfe","Ramkumar Ramachandra","Antoine Pelisse"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"218544","messageId":"195A1F16-B587-4217-97BF-6A92DA8C0786@gmail.com","threadId":"33932","inReplyTo":null,"subject":"Commit with an empty message broken since v1.8.2.1","fromName":"Mislav Marohnić","fromEmail":"mislav.marohnic@gmail.com","sentAt":"2013-05-25T19:12:06Z","receivedAt":"2013-05-25T19:12:06Z","isPatch":false,"sender":{"key":"mislav.marohnic@gmail.com","avatar":null},"body":"Commit a24a41ea9a928ccde2db074ab0835c4817223c9d introduces a bug which is still present in latest master.\n\nThis command \n\n    git commit -m \"\" --allow-empty --allow-empty-message\n\nshould create an empty commit with an empty message and never open a text editor for the commit message. Since the change, the editor is always opened.\n\nMy current workaround to skip the editor is setting the environment variable:\n\n    GIT_EDITOR=true"},{"id":"218548","messageId":"51A13086.3060004@lsrfire.ath.cx","threadId":"33932","inReplyTo":"195A1F16-B587-4217-97BF-6A92DA8C0786@gmail.com","subject":"[PATCH] commit: don't start editor if empty message is given with -m","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2013-05-25T21:43:34Z","receivedAt":"2013-05-25T21:43:34Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"If an empty message is specified with the option -m of git commit then\nthe editor is started.  That's unexpected and unnecessary.  Instead of\nusing the length of the message string for checking if the user\nspecified one, directly remember if the option -m was given.\n\nReported-by: Mislav Marohnić <mislav.marohnic@gmail.com>\nSigned-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n builtin/commit.c  | 10 ++++++----\n t/t7502-commit.sh | 17 +++++++++++++++++\n 2 files changed, 23 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex d2f30d9..1621dfc 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -107,7 +107,7 @@ static const char *cleanup_arg;\n \n static enum commit_whence whence;\n static int use_editor = 1, include_status = 1;\n-static int show_ignored_in_status;\n+static int show_ignored_in_status, have_option_m;\n static const char *only_include_assumed;\n static struct strbuf message = STRBUF_INIT;\n \n@@ -121,9 +121,11 @@ static enum {\n static int opt_parse_m(const struct option *opt, const char *arg, int unset)\n {\n \tstruct strbuf *buf = opt->value;\n-\tif (unset)\n+\tif (unset) {\n+\t\thave_option_m = 0;\n \t\tstrbuf_setlen(buf, 0);\n-\telse {\n+\t} else {\n+\t\thave_option_m = 1;\n \t\tif (buf->len)\n \t\t\tstrbuf_addch(buf, '\\n');\n \t\tstrbuf_addstr(buf, arg);\n@@ -975,7 +977,7 @@ static int parse_and_validate_options(int argc, const char *argv[],\n \tif (force_author && renew_authorship)\n \t\tdie(_(\"Using both --reset-author and --author does not make sense\"));\n \n-\tif (logfile || message.len || use_message || fixup_message)\n+\tif (logfile || have_option_m || use_message || fixup_message)\n \t\tuse_editor = 0;\n \tif (0 <= edit_flag)\n \t\tuse_editor = edit_flag;\ndiff --git a/t/t7502-commit.sh b/t/t7502-commit.sh\nindex a4938b1..6313da2 100755\n--- a/t/t7502-commit.sh\n+++ b/t/t7502-commit.sh\n@@ -361,6 +361,23 @@ test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '\n \ttest_cmp expect .git/result\n '\n \n+test_expect_success 'do not fire editor if -m <msg> was given' '\n+\techo tick >file &&\n+\tgit add file &&\n+\techo \"editor not started\" >.git/result &&\n+\t(GIT_EDITOR=\"\\\"$(pwd)/.git/FAKE_EDITOR\\\"\" git commit -m tick) &&\n+\ttest \"$(cat .git/result)\" = \"editor not started\"\n+'\n+\n+test_expect_success 'do not fire editor if -m \"\" was given' '\n+\techo tock >file &&\n+\tgit add file &&\n+\techo \"editor not started\" >.git/result &&\n+\t(GIT_EDITOR=\"\\\"$(pwd)/.git/FAKE_EDITOR\\\"\" \\\n+\t git commit -m \"\" --allow-empty-message) &&\n+\ttest \"$(cat .git/result)\" = \"editor not started\"\n+'\n+\n test_expect_success 'do not fire editor in the presence of conflicts' '\n \n \tgit clean -f &&\n-- \n1.8.3\n"},{"id":"218602","messageId":"1369663431-2405-1-git-send-email-artagnon@gmail.com","threadId":"33932","inReplyTo":"195A1F16-B587-4217-97BF-6A92DA8C0786@gmail.com","subject":"[PATCH] commit: don't use-editor when allow-empty-message","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-27T14:03:51Z","receivedAt":"2013-05-27T14:03:51Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Commit a24a41e (git-commit: only append a newline to -m mesg if\nnecessary, 2013-02-18) introduced a regression: when\n--allow-empty-message is used and an empty message is explicitly\nspecified with -m \"\", git commit still launches $EDITOR unnecessarily.\nThe commit (correctly) fixes opt_parse_m() to not fill in two newlines\ninto the message buffer unconditionally.  The real problem is that\nlaunching $EDITOR only depends on use_editor and whether message is\nempty.  Fix the problem by setting use_editor to 0 when\n--allow-empty-message is specified in the codepath where an explicit\nstring is passed via -m.\n\nReported-by: Mislav Marohnić <mislav.marohnic@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/commit.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex d2f30d9..1f5da9d 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -128,6 +128,8 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)\n \t\t\tstrbuf_addch(buf, '\\n');\n \t\tstrbuf_addstr(buf, arg);\n \t\tstrbuf_complete_line(buf);\n+\t\tif (allow_empty_message)\n+\t\t\tuse_editor = 0;\n \t}\n \treturn 0;\n }\n-- \n1.8.3.1.g33669de\n"},{"id":"218603","messageId":"CALkWK0nm71QAM1FSwuL4sK8JQXmaUtXegjsLMmYOK-1Aaro39A@mail.gmail.com","threadId":"33932","inReplyTo":"1369663431-2405-1-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH] commit: don't use-editor when allow-empty-message","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-27T14:07:58Z","receivedAt":"2013-05-27T14:07:58Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Ramkumar Ramachandra wrote:\n>  builtin/commit.c | 2 ++\n>  1 file changed, 2 insertions(+)\n\nI just made this dependent on the order in which options are parsed.\nIf --allow-empty-message is specified before -m \"\", it works.\nOtherwise, not.\n\nSorry about the stupidity.\n"},{"id":"218604","messageId":"1369664419-16440-1-git-send-email-artagnon@gmail.com","threadId":"33932","inReplyTo":"1369663431-2405-1-git-send-email-artagnon@gmail.com","subject":"[PATCH v2] commit: don't use-editor when allow-empty-message","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-27T14:20:19Z","receivedAt":"2013-05-27T14:20:19Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Commit a24a41e (git-commit: only append a newline to -m mesg if\nnecessary, 2013-02-18) introduced a regression: when\n--allow-empty-message is used and an empty message is explicitly\nspecified with -m \"\", git commit still launches $EDITOR unnecessarily.\nThe commit (correctly) fixes opt_parse_m() to not fill in two newlines\ninto the message buffer unconditionally.  The real problem is that\nlaunching $EDITOR only depends on use_editor and whether message is\nempty.  Fix the problem by setting explicit_message in the codepath\nwhere an explicit string is passed via -m, and then checking it before\nlaunching $EDITOR.\n\nReported-by: Mislav Marohnić <mislav.marohnic@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Works?\n\n builtin/commit.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex d2f30d9..7d72ba7 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -108,6 +108,7 @@ static const char *cleanup_arg;\n static enum commit_whence whence;\n static int use_editor = 1, include_status = 1;\n static int show_ignored_in_status;\n+static int explicit_message = 0;\n static const char *only_include_assumed;\n static struct strbuf message = STRBUF_INIT;\n \n@@ -128,6 +129,7 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)\n \t\t\tstrbuf_addch(buf, '\\n');\n \t\tstrbuf_addstr(buf, arg);\n \t\tstrbuf_complete_line(buf);\n+\t\texplicit_message = 1;\n \t}\n \treturn 0;\n }\n@@ -824,7 +826,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\t     git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))\n \t\treturn 0;\n \n-\tif (use_editor) {\n+\tif (use_editor && !explicit_message) {\n \t\tchar index[PATH_MAX];\n \t\tconst char *env[2] = { NULL };\n \t\tenv[0] =  index;\n-- \n1.8.3.1.g33669de.dirty\n"},{"id":"218608","messageId":"CALWbr2zW7BKwkNd5gU8vyE8KvMkzUMf1zTOr5X0cxsO7_4KA=Q@mail.gmail.com","threadId":"33932","inReplyTo":"1369664419-16440-1-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH v2] commit: don't use-editor when allow-empty-message","fromName":"Antoine Pelisse","fromEmail":"apelisse@gmail.com","sentAt":"2013-05-27T14:53:01Z","receivedAt":"2013-05-27T14:53:01Z","isPatch":true,"sender":{"key":"apelisse@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1929644?v=4"},"body":"So now we have two fixes for the same issue, don't we ?\nYou probably missed $gmane/225534.\n\nOn Mon, May 27, 2013 at 4:20 PM, Ramkumar Ramachandra\n<artagnon@gmail.com> wrote:\n> Commit a24a41e (git-commit: only append a newline to -m mesg if\n> necessary, 2013-02-18) introduced a regression: when\n> --allow-empty-message is used and an empty message is explicitly\n> specified with -m \"\", git commit still launches $EDITOR unnecessarily.\n> The commit (correctly) fixes opt_parse_m() to not fill in two newlines\n> into the message buffer unconditionally.  The real problem is that\n> launching $EDITOR only depends on use_editor and whether message is\n> empty.  Fix the problem by setting explicit_message in the codepath\n> where an explicit string is passed via -m, and then checking it before\n> launching $EDITOR.\n>\n> Reported-by: Mislav Marohnić <mislav.marohnic@gmail.com>\n> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n> ---\n>  Works?\n>\n>  builtin/commit.c | 4 +++-\n>  1 file changed, 3 insertions(+), 1 deletion(-)\n>\n> diff --git a/builtin/commit.c b/builtin/commit.c\n> index d2f30d9..7d72ba7 100644\n> --- a/builtin/commit.c\n> +++ b/builtin/commit.c\n> @@ -108,6 +108,7 @@ static const char *cleanup_arg;\n>  static enum commit_whence whence;\n>  static int use_editor = 1, include_status = 1;\n>  static int show_ignored_in_status;\n> +static int explicit_message = 0;\n>  static const char *only_include_assumed;\n>  static struct strbuf message = STRBUF_INIT;\n>\n> @@ -128,6 +129,7 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)\n>                         strbuf_addch(buf, '\\n');\n>                 strbuf_addstr(buf, arg);\n>                 strbuf_complete_line(buf);\n> +               explicit_message = 1;\n>         }\n>         return 0;\n>  }\n> @@ -824,7 +826,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n>                      git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))\n>                 return 0;\n>\n> -       if (use_editor) {\n> +       if (use_editor && !explicit_message) {\n>                 char index[PATH_MAX];\n>                 const char *env[2] = { NULL };\n>                 env[0] =  index;\n> --\n> 1.8.3.1.g33669de.dirty\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"218625","messageId":"CALkWK0kpDDP0Gid4aWPf-JsV5SbrVYH+s+5ncW4XuHqs0Lp7QQ@mail.gmail.com","threadId":"33932","inReplyTo":"CALWbr2zW7BKwkNd5gU8vyE8KvMkzUMf1zTOr5X0cxsO7_4KA=Q@mail.gmail.com","subject":"Re: [PATCH v2] commit: don't use-editor when allow-empty-message","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-27T17:57:00Z","receivedAt":"2013-05-27T17:57:00Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Antoine Pelisse wrote:\n> So now we have two fixes for the same issue, don't we ?\n> You probably missed $gmane/225534.\n\nGah, missed that.  Sorry for the noise.\n"}]}