@@ -422,36 +422,60 @@ def discover_lintables(options: Options) -> dict[str, Any]:
422
422
under current user and absolute for everything else.
423
423
"""
424
424
# git is preferred as it also considers .gitignore
425
- git_command_present = [
426
- * GIT_CMD ,
427
- "ls-files" ,
428
- "--cached" ,
429
- "--others" ,
430
- "--exclude-standard" ,
431
- "-z" ,
432
- ]
433
- git_command_absent = [* GIT_CMD , "ls-files" , "--deleted" , "-z" ]
434
- out = None
425
+ # As --recurse-submodules is incompatible with --others we need to run
426
+ # twice to get combined results.
427
+ commands = {
428
+ "tracked" : {
429
+ "cmd" : [
430
+ * GIT_CMD ,
431
+ "ls-files" ,
432
+ "--cached" ,
433
+ "--exclude-standard" ,
434
+ "--recurse-submodules" ,
435
+ "-z" ,
436
+ ],
437
+ "remove" : False ,
438
+ },
439
+ "others" : {
440
+ "cmd" : [
441
+ * GIT_CMD ,
442
+ "ls-files" ,
443
+ "--cached" ,
444
+ "--others" ,
445
+ "--exclude-standard" ,
446
+ "-z" ,
447
+ ],
448
+ "remove" : False ,
449
+ },
450
+ "absent" : {
451
+ "cmd" : [
452
+ * GIT_CMD ,
453
+ "ls-files" ,
454
+ "--deleted" ,
455
+ "-z" ,
456
+ ],
457
+ "remove" : True ,
458
+ },
459
+ }
435
460
461
+ out : set [str ] = set ()
436
462
try :
437
- out_present = subprocess .check_output (
438
- git_command_present , # noqa: S603
439
- stderr = subprocess .STDOUT ,
440
- text = True ,
441
- ).split ("\x00 " )[:- 1 ]
442
- _logger .info (
443
- "Discovered files to lint using: %s" ,
444
- " " .join (git_command_present ),
445
- )
446
-
447
- out_absent = subprocess .check_output (
448
- git_command_absent , # noqa: S603
449
- stderr = subprocess .STDOUT ,
450
- text = True ,
451
- ).split ("\x00 " )[:- 1 ]
452
- _logger .info ("Excluded removed files using: %s" , " " .join (git_command_absent ))
463
+ for k , value in commands .items ():
464
+ if not isinstance (value ["cmd" ], list ):
465
+ msg = f"Expected list but got { type (value ['cmd' ])} "
466
+ raise TypeError (msg )
467
+ result = subprocess .check_output (
468
+ value ["cmd" ], # noqa: S603
469
+ stderr = subprocess .STDOUT ,
470
+ text = True ,
471
+ ).split ("\x00 " )[:- 1 ]
472
+ _logger .info (
473
+ "Discovered files to lint using git (%s): %s" ,
474
+ k ,
475
+ " " .join (value ["cmd" ]),
476
+ )
477
+ out = out .union (result ) if not value ["remove" ] else out - set (result )
453
478
454
- out = set (out_present ) - set (out_absent )
455
479
except subprocess .CalledProcessError as exc :
456
480
if not (exc .returncode == 128 and "fatal: not a git repository" in exc .output ):
457
481
err = exc .output .rstrip ("\n " )
0 commit comments