commit: --amend -m '' silently fails to wipe message
authorAdam Dinwoodie <adam@dinwoodie.org>
Wed, 6 Apr 2016 17:15:03 +0000 (18:15 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Apr 2016 20:21:43 +0000 (13:21 -0700)
`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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7501-commit.sh
index 63e04277f99a08b15e12c3392f9e128147180fad..a7e9322d2f122b1200d4541c6a7e5eb30c063e5e 100755 (executable)
@@ -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 &&