merge: Honor prepare-commit-msg return code
authorAntoine Pelisse <apelisse@gmail.com>
Wed, 2 Jan 2013 18:42:50 +0000 (19:42 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Jan 2013 17:10:11 +0000 (09:10 -0800)
65969d4 (merge: honor prepare-commit-msg hook, 2011-02-14) tried to
make "git commit" and "git merge" consistent, because a merge that
required user assistance has to be concluded with "git commit", but
back then only "git commit" triggered prepare-commit-msg hook.

When it added a call to run the prepare-commit-msg hook, however, it
forgot to check the exit code from the hook like "git commit" does,
and ended up replacing one inconsistency with another.

When prepare-commit-msg hook that is run from "git merge" exits with
a non-zero status, abort the commit.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge.c
t/t7505-prepare-commit-msg-hook.sh

index 0ec8f0d449e505a52166b560f43f30d8c30cfbaf..1aef5ea9ab757a92d2056c8c6a8e8fa4c0617984 100644 (file)
@@ -903,8 +903,9 @@ static void prepare_to_commit(struct commit_list *remoteheads)
        if (0 < option_edit)
                strbuf_add_lines(&msg, "# ", comment, strlen(comment));
        write_merge_msg(&msg);
-       run_hook(get_index_file(), "prepare-commit-msg",
-                git_path("MERGE_MSG"), "merge", NULL, NULL);
+       if (run_hook(get_index_file(), "prepare-commit-msg",
+                    git_path("MERGE_MSG"), "merge", NULL, NULL))
+               abort_commit(remoteheads, NULL);
        if (0 < option_edit) {
                if (launch_editor(git_path("MERGE_MSG"), NULL, NULL))
                        abort_commit(remoteheads, NULL);
index 5b4b694f1801f5c2284346f882cb496df9e7d74e..357375151d79d03d11275875dd10ceea42a3ba47 100755 (executable)
@@ -167,5 +167,19 @@ test_expect_success 'with failing hook (--no-verify)' '
 
 '
 
+test_expect_success 'with failing hook (merge)' '
+
+       git checkout -B other HEAD@{1} &&
+       echo "more" >> file &&
+       git add file &&
+       rm -f "$HOOK" &&
+       git commit -m other &&
+       write_script "$HOOK" <<-EOF
+       exit 1
+       EOF
+       git checkout - &&
+       test_must_fail git merge other
+
+'
 
 test_done