File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -88,13 +88,20 @@ def main(argv: Sequence[str] | None = None) -> int:
8888 match_key = 'files'
8989 match_val = args .files_regex
9090
91+ hook_id = args .id or args .entry or args .package_name
92+ if ' ' in hook_id :
93+ raise SystemExit (
94+ f'hook id should not contain spaces, perhaps specify --id?\n \n '
95+ f'- id: { hook_id } ' ,
96+ )
97+
9198 make_repo (
9299 args .repo_path ,
93100 name = args .package_name ,
94101 description = args .description ,
95102 language = args .language ,
96103 entry = args .entry or args .package_name ,
97- id = args . id or args . entry or args . package_name ,
104+ id = hook_id ,
98105 match_key = match_key ,
99106 match_val = match_val ,
100107 args = json .dumps (split_by_commas (args .args )),
Original file line number Diff line number Diff line change @@ -123,3 +123,19 @@ def test_main_types_or_multi(mock_make_repo):
123123 assert mock_make_repo .call_args [1 ]['match_key' ] == 'types_or'
124124 assert mock_make_repo .call_args [1 ]['match_val' ] == '[c++, c]'
125125 assert mock_make_repo .call_args [1 ]['minimum_pre_commit_version' ] == '2.9.2'
126+
127+
128+ def test_main_errors_when_hook_id_has_spaces (mock_make_repo ):
129+ with pytest .raises (SystemExit ) as excinfo :
130+ main .main ((
131+ '.' ,
132+ '--language' , 'python' ,
133+ '--package-name' , 'clang-format' ,
134+ '--entry' , 'clang-format -i' ,
135+ '--types' , 'c' ,
136+ ))
137+ msg , = excinfo .value .args
138+ assert msg == (
139+ 'hook id should not contain spaces, perhaps specify --id?\n \n '
140+ '- id: clang-format -i'
141+ )
You can’t perform that action at this time.
0 commit comments