14
14
from typing import Optional , NoReturn
15
15
16
16
CMD_TOP_LEVEL = ["git" , "rev-parse" , "--show-toplevel" ]
17
- CMD_ALL_FILES = "git ls-files -z --full-name"
18
- CMD_SOURCE_FILES = 'git ls-files -z --full-name -- "*.[cC][pP][pP]" "*.[hH]" "*.[pP][yY]" "*.[sS][hH]"'
19
- CMD_SHEBANG_FILES = "git grep --full-name --line-number -I '^#!'"
17
+ CMD_ALL_FILES = ["git" , "ls-files" , "-z" , "--full-name" ]
18
+ CMD_SOURCE_FILES = ["git" , "ls-files" , "-z" , "--full-name" , "--" , "*.[cC][pP][pP]" , "*.[hH]" , "*.[pP][yY]" , "*.[sS][hH]" ]
19
+ CMD_SHEBANG_FILES = ["git" , "grep" , "--full-name" , "--line-number" , "-I" , "^#!" ]
20
+
20
21
ALLOWED_FILENAME_REGEXP = "^[a-zA-Z0-9/_.@][a-zA-Z0-9/_.@-]*$"
21
22
ALLOWED_SOURCE_FILENAME_REGEXP = "^[a-z0-9_./-]+$"
22
23
ALLOWED_SOURCE_FILENAME_EXCEPTION_REGEXP = (
@@ -73,7 +74,7 @@ def check_all_filenames() -> int:
73
74
Checks every file in the repository against an allowed regexp to make sure only lowercase or uppercase
74
75
alphanumerics (a-zA-Z0-9), underscores (_), hyphens (-), at (@) and dots (.) are used in repository filenames.
75
76
"""
76
- filenames = check_output (CMD_ALL_FILES , shell = True ).decode ("utf8" ).rstrip ("\0 " ).split ("\0 " )
77
+ filenames = check_output (CMD_ALL_FILES ).decode ("utf8" ).rstrip ("\0 " ).split ("\0 " )
77
78
filename_regex = re .compile (ALLOWED_FILENAME_REGEXP )
78
79
failed_tests = 0
79
80
for filename in filenames :
@@ -92,7 +93,7 @@ def check_source_filenames() -> int:
92
93
93
94
Additionally there is an exception regexp for directories or files which are excepted from matching this regexp.
94
95
"""
95
- filenames = check_output (CMD_SOURCE_FILES , shell = True ).decode ("utf8" ).rstrip ("\0 " ).split ("\0 " )
96
+ filenames = check_output (CMD_SOURCE_FILES ).decode ("utf8" ).rstrip ("\0 " ).split ("\0 " )
96
97
filename_regex = re .compile (ALLOWED_SOURCE_FILENAME_REGEXP )
97
98
filename_exception_regex = re .compile (ALLOWED_SOURCE_FILENAME_EXCEPTION_REGEXP )
98
99
failed_tests = 0
@@ -111,7 +112,7 @@ def check_all_file_permissions() -> int:
111
112
112
113
Additionally checks that for executable files, the file contains a shebang line
113
114
"""
114
- filenames = check_output (CMD_ALL_FILES , shell = True ).decode ("utf8" ).rstrip ("\0 " ).split ("\0 " )
115
+ filenames = check_output (CMD_ALL_FILES ).decode ("utf8" ).rstrip ("\0 " ).split ("\0 " )
115
116
failed_tests = 0
116
117
for filename in filenames :
117
118
file_meta = FileMeta (filename )
@@ -156,7 +157,7 @@ def check_shebang_file_permissions() -> int:
156
157
"""
157
158
Checks every file that contains a shebang line to ensure it has an executable permission
158
159
"""
159
- filenames = check_output (CMD_SHEBANG_FILES , shell = True ).decode ("utf8" ).strip ().split ("\n " )
160
+ filenames = check_output (CMD_SHEBANG_FILES ).decode ("utf8" ).strip ().split ("\n " )
160
161
161
162
# The git grep command we use returns files which contain a shebang on any line within the file
162
163
# so we need to filter the list to only files with the shebang on the first line
0 commit comments