commit: skip discarding the index if there is no pre-commit hook
authorKevin Willford <kewillf@microsoft.com>
Mon, 14 Aug 2017 21:54:25 +0000 (15:54 -0600)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Aug 2017 17:19:46 +0000 (10:19 -0700)
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>
builtin/commit.c
index 2de5f6cc6401b48852d8174edcbf4e149cbe51cf..6448ef48b034cfcb3cd3f899e86bb35468c638e7 100644 (file)
@@ -943,13 +943,16 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                return 0;
        }
 
-       /*
-        * Re-read the index as pre-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.
-        */
-       discard_cache();
+       if (!no_verify && find_hook("pre-commit")) {
+               /*
+                * Re-read the index as pre-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.
+                */
+               discard_cache();
+       }
        read_cache_from(index_file);
+
        if (update_main_cache_tree(0)) {
                error(_("Error building trees"));
                return 0;