@@ -39,10 +39,15 @@ export class StagedLintProcessor {
3939 // Process each pattern in the config
4040 for ( const [ pattern , commands ] of Object . entries ( config ) ) {
4141 const matchingFiles = this . getMatchingFiles ( stagedFiles , pattern )
42- if ( matchingFiles . length === 0 )
42+ if ( matchingFiles . length === 0 ) {
43+ this . log ( `No files match pattern "${ pattern } " - skipping` )
4344 continue
45+ }
4446
45- this . log ( `Processing pattern "${ pattern } " for ${ matchingFiles . length } files` )
47+ this . log ( `Pattern "${ pattern } " matched ${ matchingFiles . length } file(s)` )
48+ if ( this . verbose ) {
49+ this . log ( `Matched files: ${ matchingFiles . join ( ', ' ) } ` )
50+ }
4651
4752 const commandArray = Array . isArray ( commands ) ? commands : [ commands ]
4853
@@ -207,7 +212,11 @@ export class StagedLintProcessor {
207212 ? command . replace ( '{files}' , files . join ( ' ' ) )
208213 : `${ command } ${ files . join ( ' ' ) } `
209214
210- this . log ( `Running: ${ finalCommand } ` )
215+ this . log ( `Running command on ${ files . length } file(s): ${ command } ` )
216+ if ( this . verbose ) {
217+ this . log ( `Files: ${ files . join ( ', ' ) } ` )
218+ this . log ( `Full command: ${ finalCommand } ` )
219+ }
211220
212221 const result = execSync ( finalCommand , {
213222 cwd : this . projectRoot ,
@@ -219,6 +228,7 @@ export class StagedLintProcessor {
219228 console . warn ( result )
220229 }
221230
231+ this . log ( `Command completed successfully for ${ files . length } file(s)` )
222232 return true
223233 }
224234 catch ( error : any ) {
@@ -228,6 +238,7 @@ export class StagedLintProcessor {
228238 if ( error . stderr )
229239 console . error ( '[ERROR] Command stderr:' , error . stderr )
230240 console . error ( `[ERROR] Command failed: ${ command } ` )
241+ console . error ( `[ERROR] Failed on files: ${ files . join ( ', ' ) } ` )
231242 return false
232243 }
233244 }
@@ -361,12 +372,16 @@ export async function runStagedLint(
361372 config : GitHooksConfig ,
362373 projectRoot : string ,
363374 verbose : boolean = false ,
375+ autoRestage ?: boolean ,
364376) : Promise < boolean > {
365377 if ( ! config ) {
366378 console . error ( `[ERROR] No configuration found` )
367379 return false
368380 }
369381
382+ // Determine autoRestage setting: CLI option > hook config > global config > default true
383+ let shouldAutoRestage = autoRestage !== undefined ? autoRestage : true
384+
370385 // Try both the original hook name and its mapped version
371386 const hookVariants = [ hook , HOOK_NAME_MAP [ hook ] ] . filter ( Boolean )
372387
@@ -377,8 +392,15 @@ export async function runStagedLint(
377392 if ( typeof hookConfig === 'object' && ! Array . isArray ( hookConfig ) ) {
378393 const stagedLintConfig = ( hookConfig as { 'stagedLint' ?: StagedLintConfig , 'staged-lint' ?: StagedLintConfig } ) . stagedLint
379394 || ( hookConfig as { 'stagedLint' ?: StagedLintConfig , 'staged-lint' ?: StagedLintConfig } ) [ 'staged-lint' ]
395+
396+ // Check for hook-specific autoRestage setting
397+ const hookAutoRestage = ( hookConfig as { autoRestage ?: boolean } ) . autoRestage
398+ if ( autoRestage === undefined && hookAutoRestage !== undefined ) {
399+ shouldAutoRestage = hookAutoRestage
400+ }
401+
380402 if ( stagedLintConfig ) {
381- const processor = new StagedLintProcessor ( projectRoot , verbose , true )
403+ const processor = new StagedLintProcessor ( projectRoot , verbose , shouldAutoRestage )
382404 return processor . process ( stagedLintConfig )
383405 }
384406 }
@@ -387,7 +409,12 @@ export async function runStagedLint(
387409
388410 // If no hook-specific configuration, check for global stagedLint
389411 if ( config . stagedLint || config [ 'staged-lint' ] ) {
390- const processor = new StagedLintProcessor ( projectRoot , verbose , true )
412+ // Use global autoRestage if no CLI override
413+ if ( autoRestage === undefined && config . autoRestage !== undefined ) {
414+ shouldAutoRestage = config . autoRestage
415+ }
416+
417+ const processor = new StagedLintProcessor ( projectRoot , verbose , shouldAutoRestage )
391418 return processor . process ( config . stagedLint || config [ 'staged-lint' ] ! )
392419 }
393420
0 commit comments