Skip to content

Commit 680ee55

Browse files
Kevin Willfordgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d9c5b5 commit 680ee55

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

builtin/commit.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,16 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
943943
return 0;
944944
}
945945

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+
}
952954
read_cache_from(index_file);
955+
953956
if (update_main_cache_tree(0)) {
954957
error(_("Error building trees"));
955958
return 0;

0 commit comments

Comments
 (0)