@@ -254,24 +254,6 @@ impl HookBuilder {
254254 }
255255 }
256256
257- /// Fill in the default values for the hook configuration.
258- fn fill_in_defaults ( & mut self ) {
259- let options = & mut self . hook_spec . options ;
260- options. language_version . get_or_insert_default ( ) ;
261- options. alias . get_or_insert_default ( ) ;
262- options. args . get_or_insert_default ( ) ;
263- options. env . get_or_insert_default ( ) ;
264- options. types . get_or_insert ( vec ! [ "file" . to_string( ) ] ) ;
265- options. types_or . get_or_insert_default ( ) ;
266- options. exclude_types . get_or_insert_default ( ) ;
267- options. always_run . get_or_insert ( false ) ;
268- options. fail_fast . get_or_insert ( false ) ;
269- options. pass_filenames . get_or_insert ( true ) ;
270- options. require_serial . get_or_insert ( false ) ;
271- options. verbose . get_or_insert ( false ) ;
272- options. additional_dependencies . get_or_insert_default ( ) ;
273- }
274-
275257 /// Check the hook configuration.
276258 fn check ( & self ) -> Result < ( ) , Error > {
277259 let language = self . hook_spec . language ;
@@ -332,10 +314,26 @@ impl HookBuilder {
332314 self . hook_spec . apply_project_defaults ( self . project . config ( ) ) ;
333315
334316 self . check ( ) ?;
335- self . fill_in_defaults ( ) ;
336317
337318 let options = self . hook_spec . options ;
338- let language_version = options. language_version . expect ( "language_version not set" ) ;
319+ let language_version = options. language_version . unwrap_or_default ( ) ;
320+ let alias = options. alias . unwrap_or_default ( ) ;
321+ let args = options. args . unwrap_or_default ( ) ;
322+ let env = options. env . unwrap_or_default ( ) ;
323+ let types = options. types . unwrap_or_else ( || vec ! [ "file" . to_string( ) ] ) ;
324+ let types_or = options. types_or . unwrap_or_default ( ) ;
325+ let exclude_types = options. exclude_types . unwrap_or_default ( ) ;
326+ let always_run = options. always_run . unwrap_or_default ( ) ;
327+ let fail_fast = options. fail_fast . unwrap_or_default ( ) ;
328+ let pass_filenames = options. pass_filenames . unwrap_or ( true ) ;
329+ let require_serial = options. require_serial . unwrap_or ( false ) ;
330+ let verbose = options. verbose . unwrap_or ( false ) ;
331+ let additional_dependencies = options
332+ . additional_dependencies
333+ . unwrap_or_default ( )
334+ . into_iter ( )
335+ . collect :: < FxHashSet < _ > > ( ) ;
336+
339337 let language_request = LanguageRequest :: parse ( self . hook_spec . language , & language_version)
340338 . map_err ( |e| Error :: Hook {
341339 hook : self . hook_spec . id . clone ( ) ,
@@ -344,12 +342,6 @@ impl HookBuilder {
344342
345343 let entry = Entry :: new ( self . hook_spec . id . clone ( ) , self . hook_spec . entry ) ;
346344
347- let additional_dependencies = options
348- . additional_dependencies
349- . expect ( "additional_dependencies should not be None" )
350- . into_iter ( )
351- . collect :: < FxHashSet < _ > > ( ) ;
352-
353345 let stages = match options. stages {
354346 Some ( stages) => {
355347 let stages: FxHashSet < _ > = stages. into_iter ( ) . collect ( ) ;
@@ -368,34 +360,35 @@ impl HookBuilder {
368360 . unwrap_or ( u32:: try_from ( self . idx ) . expect ( "idx too large" ) ) ;
369361
370362 let mut hook = Hook {
371- entry,
372- stages,
373- language_request,
374- additional_dependencies,
375363 dependencies : OnceLock :: new ( ) ,
376364 project : self . project ,
377365 repo : self . repo ,
378366 idx : self . idx ,
379367 id : self . hook_spec . id ,
380368 name : self . hook_spec . name ,
381369 language : self . hook_spec . language ,
382- alias : options. alias . expect ( "alias not set" ) ,
370+
371+ priority,
372+ entry,
373+ stages,
374+ language_request,
375+ additional_dependencies,
376+ alias,
377+ types,
378+ types_or,
379+ exclude_types,
380+ args,
381+ env,
382+ always_run,
383+ fail_fast,
384+ pass_filenames,
385+ require_serial,
386+ verbose,
383387 files : options. files ,
384388 exclude : options. exclude ,
385- types : options. types . expect ( "types not set" ) ,
386- types_or : options. types_or . expect ( "types_or not set" ) ,
387- exclude_types : options. exclude_types . expect ( "exclude_types not set" ) ,
388- args : options. args . expect ( "args not set" ) ,
389- env : options. env . expect ( "env not set" ) ,
390- always_run : options. always_run . expect ( "always_run not set" ) ,
391- fail_fast : options. fail_fast . expect ( "fail_fast not set" ) ,
392- pass_filenames : options. pass_filenames . expect ( "pass_filenames not set" ) ,
393389 description : options. description ,
394390 log_file : options. log_file ,
395- require_serial : options. require_serial . expect ( "require_serial not set" ) ,
396- verbose : options. verbose . expect ( "verbose not set" ) ,
397391 minimum_prek_version : options. minimum_prek_version ,
398- priority,
399392 } ;
400393
401394 if let Err ( err) = extract_metadata_from_entry ( & mut hook) . await {
@@ -754,6 +747,14 @@ impl InstalledHook {
754747 }
755748 }
756749
750+ /// Get the directory the toolchain is installed in.
751+ pub ( crate ) fn toolchain_dir ( & self ) -> Option < & Path > {
752+ match self {
753+ InstalledHook :: Installed { info, .. } => info. toolchain . parent ( ) ,
754+ InstalledHook :: NoNeedInstall ( _) => None ,
755+ }
756+ }
757+
757758 /// Get the install info of the hook if it is installed.
758759 pub ( crate ) fn install_info ( & self ) -> Option < & InstallInfo > {
759760 match self {
0 commit comments