Skip to content

Commit c9603df

Browse files
committed
Merge branch 'cw/amend-commit-without-message' into maint
"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 f5a8400 + d9a9357 commit c9603df

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
@@ -643,7 +643,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
643643
hook_arg1 = "message";
644644
} else if (use_message) {
645645
buffer = strstr(use_message_buffer, "\n\n");
646-
if (!buffer || buffer[2] == '\0')
646+
if (!use_editor && (!buffer || buffer[2] == '\0'))
647647
die(_("commit has empty message"));
648648
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
649649
hook_arg1 = "commit";

t/t7501-commit.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ test_expect_success '--amend --edit' '
148148
test_cmp expect msg
149149
'
150150

151+
test_expect_success '--amend --edit of empty message' '
152+
cat >replace <<-\EOF &&
153+
#!/bin/sh
154+
echo "amended" >"$1"
155+
EOF
156+
chmod 755 replace &&
157+
git commit --allow-empty --allow-empty-message -m "" &&
158+
echo more bongo >file &&
159+
git add file &&
160+
EDITOR=./replace git commit --edit --amend &&
161+
git diff-tree -s --format=%s HEAD >msg &&
162+
./replace expect &&
163+
test_cmp expect msg
164+
'
165+
151166
test_expect_success '-m --edit' '
152167
echo amended >expect &&
153168
git commit --allow-empty -m buffer &&

0 commit comments

Comments
 (0)