From 1d811d9b0b655fa648001ca479a0b7da9ebd7b8c Mon Sep 17 00:00:00 2001 From: Max R Date: Thu, 28 May 2026 18:14:31 -0400 Subject: [PATCH] Return an error for invalid --repo --- pre_commit/commands/autoupdate.py | 7 +++++++ tests/commands/autoupdate_test.py | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py index aa0c5e25e..f07e54b80 100644 --- a/pre_commit/commands/autoupdate.py +++ b/pre_commit/commands/autoupdate.py @@ -175,6 +175,13 @@ def autoupdate( repo for repo in load_config(config_file)['repos'] if repo['repo'] not in {LOCAL, META} ] + missing_repos = set(repos) - {r['repo'] for r in config_repos} + if missing_repos: + output.write_line( + f'repos ({", ".join(sorted(missing_repos))}) were ' + f'not found in {config_file}', + ) + return 1 rev_infos: list[RevInfo | None] = [None] * len(config_repos) jobs = jobs or xargs.cpu_count() # 0 => number of cpus diff --git a/tests/commands/autoupdate_test.py b/tests/commands/autoupdate_test.py index 71bd04446..cbf22f393 100644 --- a/tests/commands/autoupdate_test.py +++ b/tests/commands/autoupdate_test.py @@ -260,8 +260,8 @@ def test_autoupdate_out_of_date_repo_with_correct_repo_name( assert 'local' in after -def test_autoupdate_out_of_date_repo_with_wrong_repo_name( - out_of_date, in_tmpdir, +def test_autoupdate_missing_repo_name( + out_of_date, in_tmpdir, cap_out, ): config = make_config_from_repo( 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( with open(C.CONFIG_FILE) as f: before = f.read() - # It will not update it, because the name doesn't match ret = autoupdate( C.CONFIG_FILE, freeze=False, tags_only=False, - repos=('dne',), + repos=('dne', 'foo'), ) with open(C.CONFIG_FILE) as f: after = f.read() - assert ret == 0 + assert ret == 1 assert before == after + assert cap_out.get() == ( + f"repos (dne, foo) were not found in {C.CONFIG_FILE}\n" + ) def test_does_not_reformat(tmpdir, out_of_date):