Merge branch 'cw/amend-commit-without-message' into maint
authorJunio C Hamano <gitster@pobox.com>
Sun, 22 Jul 2012 20:03:52 +0000 (13:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Jul 2012 20:03:52 +0000 (13:03 -0700)
"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

builtin/commit.c
t/t7501-commit.sh
index 3c3385cded56d41e1361b0f8d73cc99ff2bb9682..95eeab1d5146628277b0ba2c4e4bc7a6f77f3a4a 100644 (file)
@@ -643,7 +643,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                hook_arg1 = "message";
        } else if (use_message) {
                buffer = strstr(use_message_buffer, "\n\n");
-               if (!buffer || buffer[2] == '\0')
+               if (!use_editor && (!buffer || buffer[2] == '\0'))
                        die(_("commit has empty message"));
                strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
                hook_arg1 = "commit";
index 3f364a20e855f59e685dc424f51d93d7d7d8d7b9..195e7477d883f39d51f5740b5b309a489dd92d3d 100755 (executable)
@@ -148,6 +148,21 @@ test_expect_success '--amend --edit' '
        test_cmp expect msg
 '
 
+test_expect_success '--amend --edit of empty message' '
+       cat >replace <<-\EOF &&
+       #!/bin/sh
+       echo "amended" >"$1"
+       EOF
+       chmod 755 replace &&
+       git commit --allow-empty --allow-empty-message -m "" &&
+       echo more bongo >file &&
+       git add file &&
+       EDITOR=./replace git commit --edit --amend &&
+       git diff-tree -s --format=%s HEAD >msg &&
+       ./replace expect &&
+       test_cmp expect msg
+'
+
 test_expect_success '-m --edit' '
        echo amended >expect &&
        git commit --allow-empty -m buffer &&