@@ -236,16 +236,28 @@ impl CommitPopup {
236236
237237 if verify {
238238 // run pre commit hook - can reject commit
239- if let HookResult :: NotOk ( e) =
240- sync:: hooks_pre_commit_with_timeout (
241- & self . repo . borrow ( ) ,
242- self . get_hook_timeout ( ) ,
243- ) ? {
244- log:: error!( "pre-commit hook error: {}" , e) ;
245- self . queue . push ( InternalEvent :: ShowErrorMsg (
246- format ! ( "pre-commit hook error:\n {e}" ) ,
247- ) ) ;
248- return Ok ( CommitResult :: Aborted ) ;
239+ match sync:: hooks_pre_commit_with_timeout (
240+ & self . repo . borrow ( ) ,
241+ self . get_hook_timeout ( ) ,
242+ ) ? {
243+ HookResult :: NotOk ( e) => {
244+ log:: error!( "pre-commit hook error: {}" , e) ;
245+ self . queue . push ( InternalEvent :: ShowErrorMsg (
246+ format ! ( "pre-commit hook error:\n {e}" ) ,
247+ ) ) ;
248+ return Ok ( CommitResult :: Aborted ) ;
249+ }
250+ HookResult :: TimedOut => {
251+ log:: error!( "pre-commit hook timed out" ) ;
252+ self . queue . push ( InternalEvent :: ShowErrorMsg (
253+ format ! (
254+ "pre-commit hook timed out after {} seconds" ,
255+ self . get_hook_timeout( ) . as_secs( )
256+ ) ,
257+ ) ) ;
258+ return Ok ( CommitResult :: Aborted ) ;
259+ }
260+ HookResult :: Ok => { }
249261 }
250262 }
251263
@@ -254,30 +266,53 @@ impl CommitPopup {
254266
255267 if verify {
256268 // run commit message check hook - can reject commit
257- if let HookResult :: NotOk ( e) =
258- sync:: hooks_commit_msg_with_timeout (
259- & self . repo . borrow ( ) ,
260- & mut msg,
261- self . get_hook_timeout ( ) ,
262- ) ? {
263- log:: error!( "commit-msg hook error: {}" , e) ;
264- self . queue . push ( InternalEvent :: ShowErrorMsg (
265- format ! ( "commit-msg hook error:\n {e}" ) ,
266- ) ) ;
267- return Ok ( CommitResult :: Aborted ) ;
269+ match sync:: hooks_commit_msg_with_timeout (
270+ & self . repo . borrow ( ) ,
271+ & mut msg,
272+ self . get_hook_timeout ( ) ,
273+ ) ? {
274+ HookResult :: NotOk ( e) => {
275+ log:: error!( "commit-msg hook error: {}" , e) ;
276+ self . queue . push ( InternalEvent :: ShowErrorMsg (
277+ format ! ( "commit-msg hook error:\n {e}" ) ,
278+ ) ) ;
279+ return Ok ( CommitResult :: Aborted ) ;
280+ }
281+ HookResult :: TimedOut => {
282+ log:: error!( "commit-msg hook timed out" ) ;
283+ self . queue . push ( InternalEvent :: ShowErrorMsg (
284+ format ! (
285+ "commit-msg hook timed out after {} seconds" ,
286+ self . get_hook_timeout( ) . as_secs( )
287+ ) ,
288+ ) ) ;
289+ return Ok ( CommitResult :: Aborted ) ;
290+ }
291+ HookResult :: Ok => { }
268292 }
269293 }
270294 self . do_commit ( & msg) ?;
271295
272- if let HookResult :: NotOk ( e) =
273- sync:: hooks_post_commit_with_timeout (
274- & self . repo . borrow ( ) ,
275- self . get_hook_timeout ( ) ,
276- ) ? {
277- log:: error!( "post-commit hook error: {}" , e) ;
278- self . queue . push ( InternalEvent :: ShowErrorMsg ( format ! (
279- "post-commit hook error:\n {e}"
280- ) ) ) ;
296+ match sync:: hooks_post_commit_with_timeout (
297+ & self . repo . borrow ( ) ,
298+ self . get_hook_timeout ( ) ,
299+ ) ? {
300+ HookResult :: NotOk ( e) => {
301+ log:: error!( "post-commit hook error: {}" , e) ;
302+ self . queue . push ( InternalEvent :: ShowErrorMsg (
303+ format ! ( "post-commit hook error:\n {e}" ) ,
304+ ) ) ;
305+ }
306+ HookResult :: TimedOut => {
307+ log:: error!( "post-commit hook timed out" ) ;
308+ self . queue . push ( InternalEvent :: ShowErrorMsg (
309+ format ! (
310+ "post-commit hook timed out after {} seconds" ,
311+ self . get_hook_timeout( ) . as_secs( )
312+ ) ,
313+ ) ) ;
314+ }
315+ HookResult :: Ok => { }
281316 }
282317
283318 Ok ( CommitResult :: CommitDone )
@@ -488,10 +523,11 @@ impl CommitPopup {
488523 Ok ( msg)
489524 }
490525
491- // TODO - Configurable timeout
492- #[ allow( clippy:: unused_self, clippy:: missing_const_for_fn) ]
493526 fn get_hook_timeout ( & self ) -> Duration {
494- Duration :: from_secs ( 5 )
527+ self . options
528+ . borrow ( )
529+ . hook_timeout ( )
530+ . unwrap_or ( Duration :: ZERO )
495531 }
496532}
497533
0 commit comments