git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] commit: check for empty message before the check for untouched template
@ 2017-07-17 15:36 Kaartic Sivaraam
  2017-07-17 20:12 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Kaartic Sivaraam @ 2017-07-17 15:36 UTC (permalink / raw)
  To: gitster; +Cc: git

The check for whether the template given to 'git commit' is untouched
is done before the empty message check. This results in a wrong error
message being displayed in the following case. When the user removes
everything in template completely to abort the commit he is shown the
"template untouched" error which is wrong. He should be shown the
"empty message" error.

Do the empty message check before checking for an untouched template
thus fixing this issue.

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
---
 builtin/commit.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index aff6bf7aa..9c299d792 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1736,19 +1736,19 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	if (verbose || /* Truncate the message just before the diff, if any. */
 	    cleanup_mode == CLEANUP_SCISSORS)
 		strbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len));
-
 	if (cleanup_mode != CLEANUP_NONE)
 		strbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL);
-	if (template_untouched(&sb) && !allow_empty_message) {
-		rollback_index_files();
-		fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
-		exit(1);
-	}
+
 	if (message_is_empty(&sb) && !allow_empty_message) {
 		rollback_index_files();
 		fprintf(stderr, _("Aborting commit due to empty commit message.\n"));
 		exit(1);
 	}
+	if (template_untouched(&sb) && !allow_empty_message) {
+		rollback_index_files();
+		fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
+		exit(1);
+	}
 
 	if (amend) {
 		const char *exclude_gpgsig[2] = { "gpgsig", NULL };
-- 
2.13.3.973.gaaf39e6bd.dirty


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] commit: check for empty message before the check for untouched template
  2017-07-17 15:36 [PATCH] commit: check for empty message before the check for untouched template Kaartic Sivaraam
@ 2017-07-17 20:12 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2017-07-17 20:12 UTC (permalink / raw)
  To: Kaartic Sivaraam; +Cc: git

Kaartic Sivaraam <kaarticsivaraam91196@gmail.com> writes:

> The check for whether the template given to 'git commit' is untouched
> is done before the empty message check. This results in a wrong error
> message being displayed in the following case. When the user removes
> everything in template completely to abort the commit he is shown the
> "template untouched" error which is wrong. He should be shown the
> "empty message" error.
>
> Do the empty message check before checking for an untouched template
> thus fixing this issue.
>
> Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
> ---
>  builtin/commit.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

Makes sense to me.

> diff --git a/builtin/commit.c b/builtin/commit.c
> index aff6bf7aa..9c299d792 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1736,19 +1736,19 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>  	if (verbose || /* Truncate the message just before the diff, if any. */
>  	    cleanup_mode == CLEANUP_SCISSORS)
>  		strbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len));
> -
>  	if (cleanup_mode != CLEANUP_NONE)
>  		strbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL);
> -	if (template_untouched(&sb) && !allow_empty_message) {
> -		rollback_index_files();
> -		fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
> -		exit(1);
> -	}
> +
>  	if (message_is_empty(&sb) && !allow_empty_message) {
>  		rollback_index_files();
>  		fprintf(stderr, _("Aborting commit due to empty commit message.\n"));
>  		exit(1);
>  	}
> +	if (template_untouched(&sb) && !allow_empty_message) {
> +		rollback_index_files();
> +		fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
> +		exit(1);
> +	}
>  
>  	if (amend) {
>  		const char *exclude_gpgsig[2] = { "gpgsig", NULL };

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-17 20:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-17 15:36 [PATCH] commit: check for empty message before the check for untouched template Kaartic Sivaraam
2017-07-17 20:12 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).