Skip to content

Commit d19fde5

Browse files
committed
produce a helpful error when --id is accidentally spaces
1 parent d53255a commit d19fde5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pre_commit_mirror_maker/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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)),

tests/main_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
)

0 commit comments

Comments
 (0)