From 7f2cbda4de7d854d3e9f475b1e762058858d6167 Mon Sep 17 00:00:00 2001 From: Max R Date: Thu, 28 May 2026 18:23:52 -0400 Subject: [PATCH] Warn for invalid --repo --- pre_commit/commands/autoupdate.py | 11 +++++++++++ tests/commands/autoupdate_test.py | 11 +++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py index aa0c5e25e..80c9a3b78 100644 --- a/pre_commit/commands/autoupdate.py +++ b/pre_commit/commands/autoupdate.py @@ -1,6 +1,7 @@ from __future__ import annotations import concurrent.futures +import logging import os.path import re import tempfile @@ -24,6 +25,8 @@ from pre_commit.yaml import yaml_dump from pre_commit.yaml import yaml_load +logger = logging.getLogger('pre_commit') + class RevInfo(NamedTuple): repo: str @@ -176,6 +179,14 @@ def autoupdate( if repo['repo'] not in {LOCAL, META} ] + missing_repos = set(repos) - {r['repo'] for r in config_repos} + if missing_repos: + logger.warning( + f'repos {", ".join(sorted(missing_repos))!r} were ' + f'not found in {config_file}. this will return ' + 'an error in a future release.', + ) + rev_infos: list[RevInfo | None] = [None] * len(config_repos) jobs = jobs or xargs.cpu_count() # 0 => number of cpus jobs = min(jobs, len(repos) or len(config_repos)) # max 1-per-thread diff --git a/tests/commands/autoupdate_test.py b/tests/commands/autoupdate_test.py index 71bd04446..6165a62ee 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, caplog, in_tmpdir, ): config = make_config_from_repo( out_of_date.path, rev=out_of_date.original_rev, check=False, @@ -270,15 +270,18 @@ 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 before == after + assert caplog.records[0].message == ( + "repos 'dne, foo' were not found in .pre-commit-config.yaml. " + 'this will return an error in a future release.' + ) def test_does_not_reformat(tmpdir, out_of_date):