git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] commit: check for empty message before the check for untouched template
Date: Mon, 17 Jul 2017 13:12:02 -0700	[thread overview]
Message-ID: <xmqqh8yahlgt.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170717153615.16252-1-kaarticsivaraam91196@gmail.com> (Kaartic Sivaraam's message of "Mon, 17 Jul 2017 21:06:15 +0530")

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 };

      reply	other threads:[~2017-07-17 20:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqh8yahlgt.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=kaarticsivaraam91196@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).