Skip to content

Commit 8647b58

Browse files
committed
Merge branch 'cw/amend-commit-without-message'
"commit --amend" used to refuse amending a commit with an empty log message, with or without "--allow-empty-message". * cw/amend-commit-without-message: Allow edit of empty message with commit --amend
2 parents d06414b + d9a9357 commit 8647b58

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
640640
hook_arg1 = "message";
641641
} else if (use_message) {
642642
buffer = strstr(use_message_buffer, "\n\n");
643-
if (!buffer || buffer[2] == '\0')
643+
if (!use_editor && (!buffer || buffer[2] == '\0'))
644644
die(_("commit has empty message"));
645645
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
646646
hook_arg1 = "commit";

t/t7501-commit.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ test_expect_success '--amend --edit' '
138138
test_cmp expect msg
139139
'
140140

141+
test_expect_success '--amend --edit of empty message' '
142+
cat >replace <<-\EOF &&
143+
#!/bin/sh
144+
echo "amended" >"$1"
145+
EOF
146+
chmod 755 replace &&
147+
git commit --allow-empty --allow-empty-message -m "" &&
148+
echo more bongo >file &&
149+
git add file &&
150+
EDITOR=./replace git commit --edit --amend &&
151+
git diff-tree -s --format=%s HEAD >msg &&
152+
./replace expect &&
153+
test_cmp expect msg
154+
'
155+
141156
test_expect_success '-m --edit' '
142157
echo amended >expect &&
143158
git commit --allow-empty -m buffer &&

0 commit comments

Comments
 (0)