mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Merge pull request #3583 from pre-commit/forward-compat-map-manifest
add forward-compat error message
This commit is contained in:
commit
9c7ea88ab9
2 changed files with 27 additions and 1 deletions
|
|
@ -270,10 +270,19 @@ class InvalidManifestError(FatalError):
|
|||
pass
|
||||
|
||||
|
||||
def _load_manifest_forward_compat(contents: str) -> object:
|
||||
obj = yaml_load(contents)
|
||||
if isinstance(obj, dict):
|
||||
check_min_version('5')
|
||||
raise AssertionError('unreachable')
|
||||
else:
|
||||
return obj
|
||||
|
||||
|
||||
load_manifest = functools.partial(
|
||||
cfgv.load_from_filename,
|
||||
schema=MANIFEST_SCHEMA,
|
||||
load_strategy=yaml_load,
|
||||
load_strategy=_load_manifest_forward_compat,
|
||||
exc_tp=InvalidManifestError,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ from pre_commit.clientlib import CONFIG_HOOK_DICT
|
|||
from pre_commit.clientlib import CONFIG_REPO_DICT
|
||||
from pre_commit.clientlib import CONFIG_SCHEMA
|
||||
from pre_commit.clientlib import DEFAULT_LANGUAGE_VERSION
|
||||
from pre_commit.clientlib import InvalidManifestError
|
||||
from pre_commit.clientlib import load_manifest
|
||||
from pre_commit.clientlib import MANIFEST_HOOK_DICT
|
||||
from pre_commit.clientlib import MANIFEST_SCHEMA
|
||||
from pre_commit.clientlib import META_HOOK_DICT
|
||||
|
|
@ -588,3 +590,18 @@ def test_config_hook_stages_defaulting():
|
|||
'id': 'fake-hook',
|
||||
'stages': ['commit-msg', 'pre-push', 'pre-commit', 'pre-merge-commit'],
|
||||
}
|
||||
|
||||
|
||||
def test_manifest_v5_forward_compat(tmp_path):
|
||||
manifest = tmp_path.joinpath('.pre-commit-hooks.yaml')
|
||||
manifest.write_text('hooks: {}')
|
||||
|
||||
with pytest.raises(InvalidManifestError) as excinfo:
|
||||
load_manifest(manifest)
|
||||
assert str(excinfo.value) == (
|
||||
f'\n'
|
||||
f'==> File {manifest}\n'
|
||||
f'=====> \n'
|
||||
f'=====> pre-commit version 5 is required but version {C.VERSION} '
|
||||
f'is installed. Perhaps run `pip install --upgrade pre-commit`.'
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue