Skip to content

Commit

Permalink
Merge branch 'ad/commit-have-m-option'
Browse files Browse the repository at this point in the history
"git commit" misbehaved in a few minor ways when an empty message
is given via -m '', all of which has been corrected.

* ad/commit-have-m-option:
  commit: do not ignore an empty message given by -m ''
  commit: --amend -m '' silently fails to wipe message
  • Loading branch information
gitster committed Apr 22, 2016
2 parents 56b5a91 + 27014cb commit 0709261
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions builtin/commit.c
Expand Up @@ -695,7 +695,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, "-")) {
Expand Down Expand Up @@ -1172,9 +1172,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;
Expand Down
20 changes: 20 additions & 0 deletions t/t7501-commit.sh
Expand Up @@ -200,6 +200,26 @@ test_expect_success '--amend --edit of empty message' '
test_cmp expect msg
'

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 "" &&
git diff-tree -s --format=%s HEAD >msg &&
echo "" >expect &&
test_cmp expect msg
'

test_expect_success '--amend to set empty message needs --allow-empty-message' '
echo conga >file &&
git add file &&
git commit -m "unamended" &&
test_must_fail git commit --amend -m "" &&
git diff-tree -s --format=%s HEAD >msg &&
echo "unamended" >expect &&
test_cmp expect msg
'

test_expect_success '-m --edit' '
echo amended >expect &&
git commit --allow-empty -m buffer &&
Expand Down

0 comments on commit 0709261

Please sign in to comment.