Skip to content

Commit e88155d

Browse files
committed
Merge branch 'jk/commit-C-pick-empty'
"git commit --allow-empty-message -C $commit" did not work when the commit did not have any log message. * jk/commit-C-pick-empty: commit: do not complain of empty messages from -C
2 parents 561d952 + 076cbd6 commit e88155d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

builtin/commit.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
676676
} else if (use_message) {
677677
char *buffer;
678678
buffer = strstr(use_message_buffer, "\n\n");
679-
if (!use_editor && (!buffer || buffer[2] == '\0'))
680-
die(_("commit has empty message"));
681-
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
679+
if (buffer)
680+
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
682681
hook_arg1 = "commit";
683682
hook_arg2 = use_message;
684683
} else if (fixup_message) {

t/t7500-commit.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ test_expect_success 'Commit without message is allowed with --allow-empty-messag
223223
git add foo &&
224224
>empty &&
225225
git commit --allow-empty-message <empty &&
226-
commit_msg_is ""
226+
commit_msg_is "" &&
227+
git tag empty-message-commit
227228
'
228229

229230
test_expect_success 'Commit without message is no-no without --allow-empty-message' '
@@ -240,6 +241,14 @@ test_expect_success 'Commit a message with --allow-empty-message' '
240241
commit_msg_is "hello there"
241242
'
242243

244+
test_expect_success 'commit -C empty respects --allow-empty-message' '
245+
echo more >>foo &&
246+
git add foo &&
247+
test_must_fail git commit -C empty-message-commit &&
248+
git commit -C empty-message-commit --allow-empty-message &&
249+
commit_msg_is ""
250+
'
251+
243252
commit_for_rebase_autosquash_setup () {
244253
echo "first content line" >>foo &&
245254
git add foo &&

0 commit comments

Comments
 (0)