Skip to content

Commit b663af5

Browse files
committed
Merge branch 'ap/merge-stop-at-prepare-commit-msg-failure' into maint
"git merge" started calling prepare-commit-msg hook like "git commit" does some time ago, but forgot to pay attention to the exit status of the hook. * ap/merge-stop-at-prepare-commit-msg-failure: merge: Honor prepare-commit-msg return code
2 parents 02cb8da + 3e4141d commit b663af5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

builtin/merge.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,9 @@ static void prepare_to_commit(struct commit_list *remoteheads)
800800
if (0 < option_edit)
801801
strbuf_add_lines(&msg, "# ", comment, strlen(comment));
802802
write_merge_msg(&msg);
803-
run_hook(get_index_file(), "prepare-commit-msg",
804-
git_path("MERGE_MSG"), "merge", NULL, NULL);
803+
if (run_hook(get_index_file(), "prepare-commit-msg",
804+
git_path("MERGE_MSG"), "merge", NULL, NULL))
805+
abort_commit(remoteheads, NULL);
805806
if (0 < option_edit) {
806807
if (launch_editor(git_path("MERGE_MSG"), NULL, NULL))
807808
abort_commit(remoteheads, NULL);

t/t7505-prepare-commit-msg-hook.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,19 @@ test_expect_success 'with failing hook (--no-verify)' '
167167
168168
'
169169

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+
'
170184

171185
test_done

0 commit comments

Comments
 (0)