merge: Honor prepare-commit-msg return code
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>
Antoine Pelisse committed
Jan 2, 2013 at 19:42 UTC
3e4141d08c8dc1964d53c2ce13de8876d29e6436
2 files changed
+17
-2
builtin/merge.c
+3
-2
@@ -903,8 +903,9 @@ static void prepare_to_commit(struct commit_list *remoteheads)
903
if (0 < option_edit)
904
strbuf_add_lines(&msg, "# ", comment, strlen(comment));
905
write_merge_msg(&msg);
906
- run_hook(get_index_file(), "prepare-commit-msg",
907
- git_path("MERGE_MSG"), "merge", NULL, NULL);
906
+ if (run_hook(get_index_file(), "prepare-commit-msg",
907
+ git_path("MERGE_MSG"), "merge", NULL, NULL))
908
+ abort_commit(remoteheads, NULL);
909
if (0 < option_edit) {
910
if (launch_editor(git_path("MERGE_MSG"), NULL, NULL))
911
abort_commit(remoteheads, NULL);
t/t7505-prepare-commit-msg-hook.sh
+14
@@ -167,5 +167,19 @@ test_expect_success 'with failing hook (--no-verify)' '
167
168
'
169
170
+test_expect_success 'with failing hook (merge)' '
171
+
172
+ git checkout -B other HEAD@{1} &&
173
+ echo "more" >> file &&
174
+ git add file &&
175
+ rm -f "$HOOK" &&
176
+ git commit -m other &&
177
+ write_script "$HOOK" <<-EOF
178
+ exit 1
179
+ EOF
180
+ git checkout - &&
181
+ test_must_fail git merge other
182
+
183
+'
184
185
test_done