5
5
import re
6
6
import subprocess
7
7
8
+ from detect_secrets import util
8
9
from detect_secrets .core .log import get_logger
9
10
from detect_secrets .core .secrets_collection import SecretsCollection
10
11
12
+
11
13
log = get_logger (format_string = '%(message)s' )
12
14
13
15
@@ -37,13 +39,15 @@ def initialize(
37
39
exclude_lines = exclude_lines_regex ,
38
40
)
39
41
40
- files_to_scan = list ()
42
+ files_to_scan = []
41
43
for element in path :
42
44
if os .path .isdir (element ):
43
45
if scan_all_files :
44
46
files_to_scan .extend (_get_files_recursively (element ))
45
47
else :
46
- files_to_scan .extend (_get_git_tracked_files (element ))
48
+ files = _get_git_tracked_files (element )
49
+ if files :
50
+ files_to_scan .extend (files )
47
51
elif os .path .isfile (element ):
48
52
files_to_scan .append (element )
49
53
else :
@@ -268,13 +272,16 @@ def _get_git_tracked_files(rootdir='.'):
268
272
git_files = subprocess .check_output (
269
273
[
270
274
'git' ,
275
+ '-C' , rootdir ,
271
276
'ls-files' ,
272
- rootdir ,
273
277
],
274
278
stderr = fnull ,
275
279
)
276
280
277
- return set (git_files .decode ('utf-8' ).split ())
281
+ return set ([
282
+ util .get_relative_path (rootdir , filename )
283
+ for filename in git_files .decode ('utf-8' ).split ()
284
+ ])
278
285
except subprocess .CalledProcessError :
279
286
return None
280
287
@@ -284,8 +291,8 @@ def _get_files_recursively(rootdir):
284
291
This function allows us to do so.
285
292
"""
286
293
output = []
287
- for root , dirs , files in os .walk (rootdir ):
294
+ for root , _ , files in os .walk (rootdir ):
288
295
for filename in files :
289
- output .append (os . path . join (root , filename ))
296
+ output .append (util . get_relative_path (root , filename ))
290
297
291
298
return output
0 commit comments