Skip to content

Commit 41bd1c2

Browse files
committed
Return an error for invalid --repo
1 parent 1553b46 commit 41bd1c2

2 files changed

Lines changed: 10 additions & 4 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(missing_repos)!r} 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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ 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(
263+
def test_autoupdate_missing_repo_name(
264264
out_of_date, in_tmpdir,
265265
):
266266
config = make_config_from_repo(
@@ -270,14 +270,13 @@ 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
282281

283282

0 commit comments

Comments
 (0)