From: Thomas Rast <trast@student.ethz.ch>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>, <git@vger.kernel.org>
Subject: [PATCH v2] commit: allow {--amend|-c foo} when {HEAD|foo} has empty message
Date: Tue, 28 Feb 2012 11:36:59 +0100 [thread overview]
Message-ID: <010901fbfffe0f806bb19d556ebc1e512a4697f4.1330425111.git.trast@student.ethz.ch> (raw)
In-Reply-To: <20120228091422.GC5757@sigill.intra.peff.net>
Because --amend (-c foo) internally load the message from HEAD (foo,
resp.) using the same code paths as -C, they erroneously refuse to
work at all when the message of HEAD (foo) is empty.
Remove the corresponding check under --amend and -c.
None of this behavior was ever tested (not even for -C empty_message),
so we add a whole batch of new tests.
Reported-by: Lazar Florentin <florentin.lazar@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Like the last version, plus Peff's guard for the invalid commit
format. I also received Lazar (starlay) 's identity for the
attribution.
builtin/commit.c | 4 +++-
t/t7501-commit.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 3714582..5e9a832 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -690,7 +690,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
hook_arg1 = "message";
} else if (use_message) {
buffer = strstr(use_message_buffer, "\n\n");
- if (!buffer || buffer[2] == '\0')
+ if (!buffer)
+ die(_("commit object has invalid format"));
+ if (!amend && !edit_message && buffer[2] == '\0')
die(_("commit has empty message"));
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
hook_arg1 = "commit";
diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index 8bb3833..6ab7712 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -473,4 +473,70 @@ test_expect_success 'amend can copy notes' '
'
+test_expect_success 'amend on empty commit message' '
+
+ echo bar > bar &&
+ git add bar &&
+ test_tick &&
+ git commit --allow-empty-message -m "" &&
+ git tag empty_message &&
+ git commit --amend -mnonempty &&
+ git cat-file commit HEAD | grep nonempty
+
+'
+
+test_expect_success 'amend with editor on empty commit message' '
+
+ git reset --hard empty_message &&
+ cat >editor <<-\EOF &&
+ #!/bin/sh
+ echo nonempty_one >"$1"
+ EOF
+ chmod 755 editor &&
+ EDITOR=./editor git commit --amend &&
+ git cat-file commit HEAD | grep nonempty_one
+
+'
+
+test_expect_success '--amend -C empty_message fails' '
+
+ test_commit nonempty &&
+ test_must_fail git commit --amend -C empty_message
+
+'
+
+test_expect_success '-C empty_message fails' '
+
+ echo 1 > bar &&
+ git add bar &&
+ test_must_fail git commit --amend -C empty_message
+
+'
+
+test_expect_success '--amend -c empty_message works' '
+
+ cat >editor <<-\EOF &&
+ #!/bin/sh
+ echo nonempty_two >"$1"
+ EOF
+ chmod 755 editor &&
+ EDITOR=./editor git commit --amend -c empty_message &&
+ git cat-file commit HEAD | grep nonempty_two
+
+'
+
+test_expect_success '-c empty_message works' '
+
+ echo 2 > bar &&
+ git add bar &&
+ cat >editor <<-\EOF &&
+ #!/bin/sh
+ echo nonempty_three >"$1"
+ EOF
+ chmod 755 editor &&
+ EDITOR=./editor git commit -c empty_message &&
+ git cat-file commit HEAD | grep nonempty_three
+
+'
+
test_done
--
1.7.9.2.467.g7fee4
next prev parent reply other threads:[~2012-02-28 10:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-28 8:57 [PATCH] commit: allow {--amend|-c foo} when {HEAD|foo} has empty message Thomas Rast
2012-02-28 9:05 ` Jeff King
2012-02-28 9:14 ` Jeff King
2012-02-28 9:20 ` Thomas Rast
2012-02-28 17:21 ` Junio C Hamano
2012-02-28 19:59 ` Jeff King
2012-02-28 21:12 ` Junio C Hamano
2012-02-28 10:36 ` Thomas Rast [this message]
2012-02-28 10:37 ` [RFC PATCH 2a] pretty: detect missing \n\n in commit message Thomas Rast
2012-02-28 12:56 ` Nguyen Thai Ngoc Duy
2012-02-28 17:27 ` Junio C Hamano
2012-02-28 10:37 ` [RFC PATCH 2b] parse_commit: refuse to load commit without \n\n separator Thomas Rast
2012-02-28 17:25 ` [PATCH v2] commit: allow {--amend|-c foo} when {HEAD|foo} has empty message Junio C Hamano
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=010901fbfffe0f806bb19d556ebc1e512a4697f4.1330425111.git.trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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).