git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] commit: --amend -m '' silently fails to wipe message

From
Adam Dinwoodie <adam@dinwoodie.org>
Date
Apr 6, 2016, 17:15 UTC
Message-ID
<20160406171503.GA2345@dinwoodie.org>

`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
Next: Jeff King
Message 1 of 9 in “commit: --amend -m '' silently fails to wipe message”
  1. commit: --amend -m '' silently fails to wipe messageAdam Dinwoodie, Apr 6, 2016
  2. Jeff KingApr 7, 2016
  3. Jeff KingApr 7, 2016
  4. Junio C HamanoApr 7, 2016
  5. Jeff KingApr 7, 2016
  6. Junio C HamanoApr 7, 2016
  7. Jeff KingApr 7, 2016
  8. Adam DinwoodieApr 7, 2016
  9. Jeff KingApr 7, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.