Skip to content

Commit 1d811d9

Browse files
mxrasottile
authored andcommitted
Return an error for invalid --repo
1 parent 374d354 commit 1d811d9

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎pre_commit/commands/autoupdate.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ def autoupdate(
175175
repo for repo in load_config(config_file)['repos']
176176
if repo['repo'] not in {LOCAL, META}
177177
]
178+
missing_repos = set(repos) - {r['repo'] for r in config_repos}
179+
if missing_repos:
180+
output.write_line(
181+
f'repos ({", ".join(sorted(missing_repos))}) were '
182+
f'not found in {config_file}',
183+
)
184+
return 1
178185

179186
rev_infos: list[RevInfo | None] = [None] * len(config_repos)
180187
jobs = jobs or xargs.cpu_count() # 0 => number of cpus

‎tests/commands/autoupdate_test.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ def test_autoupdate_out_of_date_repo_with_correct_repo_name(
260260
assert 'local' in after
261261

262262

263-
def test_autoupdate_out_of_date_repo_with_wrong_repo_name(
264-
out_of_date, in_tmpdir,
263+
def test_autoupdate_missing_repo_name(
264+
out_of_date, in_tmpdir, cap_out,
265265
):
266266
config = make_config_from_repo(
267267
out_of_date.path, rev=out_of_date.original_rev, check=False,
@@ -270,15 +270,17 @@ def test_autoupdate_out_of_date_repo_with_wrong_repo_name(
270270

271271
with open(C.CONFIG_FILE) as f:
272272
before = f.read()
273-
# It will not update it, because the name doesn't match
274273
ret = autoupdate(
275274
C.CONFIG_FILE, freeze=False, tags_only=False,
276-
repos=('dne',),
275+
repos=('dne', 'foo'),
277276
)
278277
with open(C.CONFIG_FILE) as f:
279278
after = f.read()
280-
assert ret == 0
279+
assert ret == 1
281280
assert before == after
281+
assert cap_out.get() == (
282+
f"repos (dne, foo) were not found in {C.CONFIG_FILE}\n"
283+
)
282284

283285

284286
def test_does_not_reformat(tmpdir, out_of_date):

0 commit comments

Comments
 (0)