Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pre_commit/commands/autoupdate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import concurrent.futures
import logging
import os.path
import re
import tempfile
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions tests/commands/autoupdate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down
Loading