Adds ERROR log message on missing manifest

When attempting to use pre-commit with a repository that does not
contain a .pre-commit-config.yaml, log an ERROR level message with
information about the problem repo before bailing out.
This commit is contained in:
Joe Kerhin 2023-12-09 21:21:16 +00:00
parent 51df34e5fb
commit b425ca2b1c

View file

@ -9,6 +9,7 @@ from typing import Any
import pre_commit.constants as C
from pre_commit.all_languages import languages
from pre_commit.clientlib import InvalidManifestError
from pre_commit.clientlib import load_manifest
from pre_commit.clientlib import LOCAL
from pre_commit.clientlib import META
@ -194,7 +195,15 @@ def _cloned_repository_hooks(
) -> tuple[Hook, ...]:
repo, rev = repo_config['repo'], repo_config['rev']
manifest_path = os.path.join(store.clone(repo, rev), C.MANIFEST_FILE)
by_id = {hook['id']: hook for hook in load_manifest(manifest_path)}
try:
by_id = {hook['id']: hook for hook in load_manifest(manifest_path)}
except InvalidManifestError as err:
if 'is not a file' in err.args[0].error_msg:
logger.error(
f'Could not find {C.MANIFEST_FILE} in {repo_config["repo"]} - '
f'Is {repo_config["repo"]} configured to use pre-config?',
)
raise err
for hook in repo_config['hooks']:
if hook['id'] not in by_id: