@@ -39,10 +39,15 @@ export class StagedLintProcessor {
39
39
// Process each pattern in the config
40
40
for ( const [ pattern , commands ] of Object . entries ( config ) ) {
41
41
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` )
43
44
continue
45
+ }
44
46
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
+ }
46
51
47
52
const commandArray = Array . isArray ( commands ) ? commands : [ commands ]
48
53
@@ -207,7 +212,11 @@ export class StagedLintProcessor {
207
212
? command . replace ( '{files}' , files . join ( ' ' ) )
208
213
: `${ command } ${ files . join ( ' ' ) } `
209
214
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
+ }
211
220
212
221
const result = execSync ( finalCommand , {
213
222
cwd : this . projectRoot ,
@@ -219,6 +228,7 @@ export class StagedLintProcessor {
219
228
console . warn ( result )
220
229
}
221
230
231
+ this . log ( `Command completed successfully for ${ files . length } file(s)` )
222
232
return true
223
233
}
224
234
catch ( error : any ) {
@@ -228,6 +238,7 @@ export class StagedLintProcessor {
228
238
if ( error . stderr )
229
239
console . error ( '[ERROR] Command stderr:' , error . stderr )
230
240
console . error ( `[ERROR] Command failed: ${ command } ` )
241
+ console . error ( `[ERROR] Failed on files: ${ files . join ( ', ' ) } ` )
231
242
return false
232
243
}
233
244
}
@@ -361,12 +372,16 @@ export async function runStagedLint(
361
372
config : GitHooksConfig ,
362
373
projectRoot : string ,
363
374
verbose : boolean = false ,
375
+ autoRestage ?: boolean ,
364
376
) : Promise < boolean > {
365
377
if ( ! config ) {
366
378
console . error ( `[ERROR] No configuration found` )
367
379
return false
368
380
}
369
381
382
+ // Determine autoRestage setting: CLI option > hook config > global config > default true
383
+ let shouldAutoRestage = autoRestage !== undefined ? autoRestage : true
384
+
370
385
// Try both the original hook name and its mapped version
371
386
const hookVariants = [ hook , HOOK_NAME_MAP [ hook ] ] . filter ( Boolean )
372
387
@@ -377,8 +392,15 @@ export async function runStagedLint(
377
392
if ( typeof hookConfig === 'object' && ! Array . isArray ( hookConfig ) ) {
378
393
const stagedLintConfig = ( hookConfig as { 'stagedLint' ?: StagedLintConfig , 'staged-lint' ?: StagedLintConfig } ) . stagedLint
379
394
|| ( 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
+
380
402
if ( stagedLintConfig ) {
381
- const processor = new StagedLintProcessor ( projectRoot , verbose , true )
403
+ const processor = new StagedLintProcessor ( projectRoot , verbose , shouldAutoRestage )
382
404
return processor . process ( stagedLintConfig )
383
405
}
384
406
}
@@ -387,7 +409,12 @@ export async function runStagedLint(
387
409
388
410
// If no hook-specific configuration, check for global stagedLint
389
411
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 )
391
418
return processor . process ( config . stagedLint || config [ 'staged-lint' ] ! )
392
419
}
393
420
0 commit comments