From 27014cbc04e369624f6c1754b72ef4eddb911166 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 7 Apr 2016 12:56:26 -0700 Subject: commit: do not ignore an empty message given by -m '' When f9568530 (builtin-commit: resurrect behavior for multiple -m options, 2007-11-11) converted a "char *message" to "struct strbuf message" to hold the messages given with the "-m" option, it incorrectly changed the checks "did we get a message with the -m option?" to "is message.len 0?". Later, we noticed one breakage from this change and corrected it with 25206778 (commit: don't start editor if empty message is given with -m, 2013-05-25). However, "we got a message with -m, even though an empty one, so we shouldn't be launching an editor" was not the only breakage. * "git commit --amend -m '' --allow-empty", even though it looks strange, is a valid request to amend the commit to have no message at all. Due to the misdetection of the presence of -m on the command line, we ended up keeping the log messsage from the original commit. * "git commit -m "$msg" -F file" should be rejected whether $msg is an empty string or not, but due to the same bug, was not rejected when $msg is empty. * "git -c template=file -m "$msg"" should ignore the template even when $msg is empty, but it didn't and instead used the contents from the template file. Correct these by checking have_option_m, which the earlier 25206778 introduced to fix the same bug. Reported-by: Adam Dinwoodie Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t7501-commit.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 't/t7501-commit.sh') diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index a7e9322d2f..900f7de05a 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -200,8 +200,8 @@ test_expect_success '--amend --edit of empty message' ' test_cmp expect msg ' -test_expect_failure '--amend to set message to empty' ' - echo batá >file && +test_expect_success '--amend to set message to empty' ' + echo bata >file && git add file && git commit -m "unamended" && git commit --amend --allow-empty-message -m "" && @@ -210,7 +210,7 @@ test_expect_failure '--amend to set message to empty' ' test_cmp expect msg ' -test_expect_failure '--amend to set empty message needs --allow-empty-message' ' +test_expect_success '--amend to set empty message needs --allow-empty-message' ' echo conga >file && git add file && git commit -m "unamended" && -- cgit v1.2.3