{"thread":{"id":"46406","subject":"[PATCH] commit: check for empty message before the check for untouched template","startedAt":"2017-07-17T15:36:20Z","lastAt":"2017-07-17T20:12:09Z","messageCount":2,"participants":["Kaartic Sivaraam","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"324643","messageId":"20170717153615.16252-1-kaarticsivaraam91196@gmail.com","threadId":"46406","inReplyTo":null,"subject":"[PATCH] commit: check for empty message before the check for untouched template","fromName":"Kaartic Sivaraam","fromEmail":"kaarticsivaraam91196@gmail.com","sentAt":"2017-07-17T15:36:15Z","receivedAt":"2017-07-17T15:36:20Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"The check for whether the template given to 'git commit' is untouched\nis done before the empty message check. This results in a wrong error\nmessage being displayed in the following case. When the user removes\neverything in template completely to abort the commit he is shown the\n\"template untouched\" error which is wrong. He should be shown the\n\"empty message\" error.\n\nDo the empty message check before checking for an untouched template\nthus fixing this issue.\n\nSigned-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>\n---\n builtin/commit.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex aff6bf7aa..9c299d792 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1736,19 +1736,19 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \tif (verbose || /* Truncate the message just before the diff, if any. */\n \t    cleanup_mode == CLEANUP_SCISSORS)\n \t\tstrbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len));\n-\n \tif (cleanup_mode != CLEANUP_NONE)\n \t\tstrbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL);\n-\tif (template_untouched(&sb) && !allow_empty_message) {\n-\t\trollback_index_files();\n-\t\tfprintf(stderr, _(\"Aborting commit; you did not edit the message.\\n\"));\n-\t\texit(1);\n-\t}\n+\n \tif (message_is_empty(&sb) && !allow_empty_message) {\n \t\trollback_index_files();\n \t\tfprintf(stderr, _(\"Aborting commit due to empty commit message.\\n\"));\n \t\texit(1);\n \t}\n+\tif (template_untouched(&sb) && !allow_empty_message) {\n+\t\trollback_index_files();\n+\t\tfprintf(stderr, _(\"Aborting commit; you did not edit the message.\\n\"));\n+\t\texit(1);\n+\t}\n \n \tif (amend) {\n \t\tconst char *exclude_gpgsig[2] = { \"gpgsig\", NULL };\n-- \n2.13.3.973.gaaf39e6bd.dirty\n\n"},{"id":"324680","messageId":"xmqqh8yahlgt.fsf@gitster.mtv.corp.google.com","threadId":"46406","inReplyTo":"20170717153615.16252-1-kaarticsivaraam91196@gmail.com","subject":"Re: [PATCH] commit: check for empty message before the check for untouched template","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-07-17T20:12:02Z","receivedAt":"2017-07-17T20:12:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kaartic Sivaraam <kaarticsivaraam91196@gmail.com> writes:\n\n> The check for whether the template given to 'git commit' is untouched\n> is done before the empty message check. This results in a wrong error\n> message being displayed in the following case. When the user removes\n> everything in template completely to abort the commit he is shown the\n> \"template untouched\" error which is wrong. He should be shown the\n> \"empty message\" error.\n>\n> Do the empty message check before checking for an untouched template\n> thus fixing this issue.\n>\n> Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>\n> ---\n>  builtin/commit.c | 12 ++++++------\n>  1 file changed, 6 insertions(+), 6 deletions(-)\n\nMakes sense to me.\n\n> diff --git a/builtin/commit.c b/builtin/commit.c\n> index aff6bf7aa..9c299d792 100644\n> --- a/builtin/commit.c\n> +++ b/builtin/commit.c\n> @@ -1736,19 +1736,19 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n>  \tif (verbose || /* Truncate the message just before the diff, if any. */\n>  \t    cleanup_mode == CLEANUP_SCISSORS)\n>  \t\tstrbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len));\n> -\n>  \tif (cleanup_mode != CLEANUP_NONE)\n>  \t\tstrbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL);\n> -\tif (template_untouched(&sb) && !allow_empty_message) {\n> -\t\trollback_index_files();\n> -\t\tfprintf(stderr, _(\"Aborting commit; you did not edit the message.\\n\"));\n> -\t\texit(1);\n> -\t}\n> +\n>  \tif (message_is_empty(&sb) && !allow_empty_message) {\n>  \t\trollback_index_files();\n>  \t\tfprintf(stderr, _(\"Aborting commit due to empty commit message.\\n\"));\n>  \t\texit(1);\n>  \t}\n> +\tif (template_untouched(&sb) && !allow_empty_message) {\n> +\t\trollback_index_files();\n> +\t\tfprintf(stderr, _(\"Aborting commit; you did not edit the message.\\n\"));\n> +\t\texit(1);\n> +\t}\n>  \n>  \tif (amend) {\n>  \t\tconst char *exclude_gpgsig[2] = { \"gpgsig\", NULL };\n"}]}