commit: skip discarding the index if there is no pre-commit hook

If there is not a pre-commit hook, there is no reason to discard the index and reread it. This change checks to presence of a pre-commit hook and then only discards the index if there was one. Signed-off-by: Kevin Willford <kewillf@microsoft.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin Willford committed Aug 14, 2017 at 15:54 UTC 680ee550d72150f27cdb3235462eee355a20038b
1 file changed +9 -6
builtin/commit.c
+9 -6
@@ -943,13 +943,16 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
943 return 0;
944 }
945
946 - /*
947 - * Re-read the index as pre-commit hook could have updated it,
948 - * and write it out as a tree. We must do this before we invoke
949 - * the editor and after we invoke run_status above.
950 - */
951 - discard_cache();
946 + if (!no_verify && find_hook("pre-commit")) {
947 + /*
948 + * Re-read the index as pre-commit hook could have updated it,
949 + * and write it out as a tree. We must do this before we invoke
950 + * the editor and after we invoke run_status above.
951 + */
952 + discard_cache();
953 + }
954 read_cache_from(index_file);
955 +
956 if (update_main_cache_tree(0)) {
957 error(_("Error building trees"));
958 return 0;