]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge: don't run post-hook logic on --no-verify
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 7 Mar 2022 12:33:45 +0000 (13:33 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Mar 2022 21:00:52 +0000 (13:00 -0800)
Fix a minor bug introduced in bc40ce4de61 (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 6098817fd7f (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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge.c

index a94a03384ae6da259a1c6abf5fcd5b4b88b8325a..b26b4c451572e61066701b4f0393b6340d79c668 100644 (file)
@@ -845,15 +845,18 @@ static void prepare_to_commit(struct commit_list *remoteheads)
        struct strbuf msg = STRBUF_INIT;
        const char *index_file = get_index_file();
 
-       if (!no_verify && run_commit_hook(0 < option_edit, index_file, "pre-merge-commit", NULL))
-               abort_commit(remoteheads, NULL);
-       /*
-        * Re-read the index as pre-merge-commit hook could have updated it,
-        * and write it out as a tree.  We must do this before we invoke
-        * the editor and after we invoke run_status above.
-        */
-       if (hook_exists("pre-merge-commit"))
-               discard_cache();
+       if (!no_verify) {
+               if (run_commit_hook(0 < option_edit, index_file,
+                                   "pre-merge-commit", NULL))
+                       abort_commit(remoteheads, NULL);
+               /*
+                * Re-read the index as pre-merge-commit hook could have updated it,
+                * and write it out as a tree.  We must do this before we invoke
+                * the editor and after we invoke run_status above.
+                */
+               if (hook_exists("pre-merge-commit"))
+                       discard_cache();
+       }
        read_cache_from(index_file);
        strbuf_addbuf(&msg, &merge_msg);
        if (squash)