git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] commit: --amend -m '' silently fails to wipe message
@ 2016-04-06 17:15 Adam Dinwoodie
  2016-04-07  4:42 ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Adam Dinwoodie @ 2016-04-06 17:15 UTC (permalink / raw)
  To: git; +Cc: Chris Webb, Jeff King, Ævar Arnfjörð Bjarmason

`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.

Signed-off-by: Adam Dinwoodie <adam@dinwoodie.org>
---

I've had to guess at the correct file to add these tests to; t7500
covers the mainline --allow-empty-message cases, while t7501 doesn't
(currently) cover --allow-empty-message but does cover --amend.  I've
made an educated guess about the correct file, but moving the new tests
to the other file should be reasonably trivial.

 t/t7501-commit.sh | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index 63e0427..a7e9322 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -200,6 +200,26 @@ test_expect_success '--amend --edit of empty message' '
 	test_cmp expect msg
 '
 
+test_expect_failure '--amend to set message to empty' '
+	echo batá >file &&
+	git add file &&
+	git commit -m "unamended" &&
+	git commit --amend --allow-empty-message -m "" &&
+	git diff-tree -s --format=%s HEAD >msg &&
+	echo "" >expect &&
+	test_cmp expect msg
+'
+
+test_expect_failure '--amend to set empty message needs --allow-empty-message' '
+	echo conga >file &&
+	git add file &&
+	git commit -m "unamended" &&
+	test_must_fail git commit --amend -m "" &&
+	git diff-tree -s --format=%s HEAD >msg &&
+	echo "unamended" >expect &&
+	test_cmp expect msg
+'
+
 test_expect_success '-m --edit' '
 	echo amended >expect &&
 	git commit --allow-empty -m buffer &&
-- 
2.7.4

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

end of thread, other threads:[~2016-04-07 20:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-06 17:15 [PATCH] commit: --amend -m '' silently fails to wipe message Adam Dinwoodie
2016-04-07  4:42 ` Jeff King
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

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).