diff --git a/builtin/commit.c b/builtin/commit.c index c2ebea4ed3..9a203bde74 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -694,7 +694,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, } } - if (message.len) { + if (have_option_m) { strbuf_addbuf(&sb, &message); hook_arg1 = "message"; } else if (logfile && !strcmp(logfile, "-")) { @@ -1162,9 +1162,9 @@ static int parse_and_validate_options(int argc, const char *argv[], f++; if (f > 1) die(_("Only one of -c/-C/-F/--fixup can be used.")); - if (message.len && f > 0) + if (have_option_m && f > 0) die((_("Option -m cannot be combined with -c/-C/-F/--fixup."))); - if (f || message.len) + if (f || have_option_m) template_file = NULL; if (edit_message) use_message = edit_message; diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index a7e9322d2f..900f7de05a 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -200,8 +200,8 @@ test_expect_success '--amend --edit of empty message' ' test_cmp expect msg ' -test_expect_failure '--amend to set message to empty' ' - echo batá >file && +test_expect_success '--amend to set message to empty' ' + echo bata >file && git add file && git commit -m "unamended" && git commit --amend --allow-empty-message -m "" && @@ -210,7 +210,7 @@ test_expect_failure '--amend to set message to empty' ' test_cmp expect msg ' -test_expect_failure '--amend to set empty message needs --allow-empty-message' ' +test_expect_success '--amend to set empty message needs --allow-empty-message' ' echo conga >file && git add file && git commit -m "unamended" &&