@@ -934,6 +934,9 @@ static int run_receive_hook(struct command *commands,
934934 int saved_stderr = -1 ;
935935 int ret ;
936936
937+ if (!hook_exists (the_repository , hook_name ))
938+ return 0 ;
939+
937940 /* if there are no valid commands, don't invoke the hook at all. */
938941 while (iter && skip_broken && (iter -> error_string || iter -> did_not_exist ))
939942 iter = iter -> next ;
@@ -974,12 +977,16 @@ static int run_receive_hook(struct command *commands,
974977
975978static int run_update_hook (struct command * cmd )
976979{
980+ static const char hook_name [] = "update" ;
977981 struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT ;
978982 struct async sideband_async ;
979983 int sideband_async_started = 0 ;
980984 int saved_stderr = -1 ;
981985 int code ;
982986
987+ if (!hook_exists (the_repository , hook_name ))
988+ return 0 ;
989+
983990 strvec_pushl (& opt .args ,
984991 cmd -> ref_name ,
985992 oid_to_hex (& cmd -> old_oid ),
@@ -988,7 +995,7 @@ static int run_update_hook(struct command *cmd)
988995
989996 prepare_sideband_async (& sideband_async , & saved_stderr , & sideband_async_started );
990997
991- code = run_hooks_opt (the_repository , "update" , & opt );
998+ code = run_hooks_opt (the_repository , hook_name , & opt );
992999
9931000 finish_sideband_async (& sideband_async , saved_stderr , sideband_async_started );
9941001
@@ -1668,12 +1675,16 @@ static const char *update(struct command *cmd, struct shallow_info *si)
16681675
16691676static void run_update_post_hook (struct command * commands )
16701677{
1678+ static const char hook_name [] = "post-update" ;
16711679 struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT ;
16721680 struct async sideband_async ;
16731681 struct command * cmd ;
16741682 int sideband_async_started = 0 ;
16751683 int saved_stderr = -1 ;
16761684
1685+ if (!hook_exists (the_repository , hook_name ))
1686+ return ;
1687+
16771688 for (cmd = commands ; cmd ; cmd = cmd -> next ) {
16781689 if (cmd -> error_string || cmd -> did_not_exist )
16791690 continue ;
@@ -1684,7 +1695,7 @@ static void run_update_post_hook(struct command *commands)
16841695
16851696 prepare_sideband_async (& sideband_async , & saved_stderr , & sideband_async_started );
16861697
1687- run_hooks_opt (the_repository , "post-update" , & opt );
1698+ run_hooks_opt (the_repository , hook_name , & opt );
16881699
16891700 finish_sideband_async (& sideband_async , saved_stderr , sideband_async_started );
16901701}
0 commit comments