Skip to content

Commit 9f6e63b

Browse files
avargitster
authored andcommitted
merge: don't run post-hook logic on --no-verify
Fix a minor bug introduced in bc40ce4 (merge: --no-verify to bypass pre-merge-commit hook, 2019-08-07), when that change made the --no-verify option bypass the "pre-merge-commit" hook it didn't update the corresponding find_hook() (later hook_exists()) condition. As can be seen in the preceding commit in 6098817 (git-merge: honor pre-merge-commit hook, 2019-08-07) the two should go hand in hand. There's no point in invoking discard_cache() here if the hook couldn't have possibly updated the index. It's buggy that we use "hook_exist()" here, and as discussed in the subsequent commit it's subject to obscure race conditions that we're about to fix, but for now this change is a strict improvement that retains any caveats to do with the use of "hooks_exist()" as-is. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c216290 commit 9f6e63b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

builtin/merge.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -845,15 +845,18 @@ static void prepare_to_commit(struct commit_list *remoteheads)
845845
struct strbuf msg = STRBUF_INIT;
846846
const char *index_file = get_index_file();
847847

848-
if (!no_verify && run_commit_hook(0 < option_edit, index_file, "pre-merge-commit", NULL))
849-
abort_commit(remoteheads, NULL);
850-
/*
851-
* Re-read the index as pre-merge-commit hook could have updated it,
852-
* and write it out as a tree. We must do this before we invoke
853-
* the editor and after we invoke run_status above.
854-
*/
855-
if (hook_exists("pre-merge-commit"))
856-
discard_cache();
848+
if (!no_verify) {
849+
if (run_commit_hook(0 < option_edit, index_file,
850+
"pre-merge-commit", NULL))
851+
abort_commit(remoteheads, NULL);
852+
/*
853+
* Re-read the index as pre-merge-commit hook could have updated it,
854+
* and write it out as a tree. We must do this before we invoke
855+
* the editor and after we invoke run_status above.
856+
*/
857+
if (hook_exists("pre-merge-commit"))
858+
discard_cache();
859+
}
857860
read_cache_from(index_file);
858861
strbuf_addbuf(&msg, &merge_msg);
859862
if (squash)

0 commit comments

Comments
 (0)