Skip to content

Commit 178e814

Browse files
me-andgitster
authored andcommitted
commit: --amend -m '' silently fails to wipe message
`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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7654286 commit 178e814

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

t/t7501-commit.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,26 @@ test_expect_success '--amend --edit of empty message' '
200200
test_cmp expect msg
201201
'
202202

203+
test_expect_failure '--amend to set message to empty' '
204+
echo batá >file &&
205+
git add file &&
206+
git commit -m "unamended" &&
207+
git commit --amend --allow-empty-message -m "" &&
208+
git diff-tree -s --format=%s HEAD >msg &&
209+
echo "" >expect &&
210+
test_cmp expect msg
211+
'
212+
213+
test_expect_failure '--amend to set empty message needs --allow-empty-message' '
214+
echo conga >file &&
215+
git add file &&
216+
git commit -m "unamended" &&
217+
test_must_fail git commit --amend -m "" &&
218+
git diff-tree -s --format=%s HEAD >msg &&
219+
echo "unamended" >expect &&
220+
test_cmp expect msg
221+
'
222+
203223
test_expect_success '-m --edit' '
204224
echo amended >expect &&
205225
git commit --allow-empty -m buffer &&

0 commit comments

Comments
 (0)