git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Adam Dinwoodie <adam@dinwoodie.org>
Cc: git@vger.kernel.org, "Chris Webb" <chris@arachsys.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH] commit: --amend -m '' silently fails to wipe message
Date: Thu, 7 Apr 2016 00:42:19 -0400	[thread overview]
Message-ID: <20160407044219.GA29710@sigill.intra.peff.net> (raw)
In-Reply-To: <20160406171503.GA2345@dinwoodie.org>

On Wed, Apr 06, 2016 at 06:15:03PM +0100, Adam Dinwoodie wrote:

> `git commit --amend -m ''` seems to be an unambiguous request to blank a
> commit message, but it actually leaves the commit message as-is.  That's
> the case regardless of whether `--allow-empty-message` is specified, and
> doesn't so much as drop a non-zero return code.
> 
> Add failing tests to show this behaviour.

Hmm. Is it just that we check "message.len", which cannot tell the
difference between "-m was not given" and "-m was given the empty
string"?

IOW, would this fix it?

diff --git a/builtin/commit.c b/builtin/commit.c
index 109742e..3cdc44e 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -695,7 +695,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		}
 	}
 
-	if (message.len) {
+	if (have_option_m) {
 		strbuf_addbuf(&sb, &message);
 		hook_arg1 = "message";
 	} else if (logfile && !strcmp(logfile, "-")) {

It passes the test suite and your two new tests, but I didn't look too
deeply to see if there are other fallouts. I don't think anybody should
be using it to counteract a previous "-m" or anything like that; we have
"--no-message" for that.

-Peff

PS Is there a previous thread? I see a couple people cc'd, including me,
   but I don't remember a previous discussion. Did I just forget it?

  reply	other threads:[~2016-04-07  4:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-06 17:15 [PATCH] commit: --amend -m '' silently fails to wipe message Adam Dinwoodie
2016-04-07  4:42 ` Jeff King [this message]
2016-04-07  4:48   ` Jeff King
2016-04-07 18:12     ` Junio C Hamano
2016-04-07 19:02       ` Jeff King
2016-04-07 19:56         ` Junio C Hamano
2016-04-07 20:28           ` Jeff King
2016-04-07  9:50   ` Adam Dinwoodie
2016-04-07 19:02     ` Jeff King

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=20160407044219.GA29710@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=adam@dinwoodie.org \
    --cc=avarab@gmail.com \
    --cc=chris@arachsys.com \
    --cc=git@vger.kernel.org \
    /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).