mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
remove support for top-level list format
This commit is contained in:
parent
40c5bdad65
commit
0024484f5b
3 changed files with 66 additions and 79 deletions
|
|
@ -391,23 +391,10 @@ class InvalidConfigError(FatalError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def ordered_load_normalize_legacy_config(contents: str) -> dict[str, Any]:
|
|
||||||
data = yaml_load(contents)
|
|
||||||
if isinstance(data, list):
|
|
||||||
logger.warning(
|
|
||||||
'normalizing pre-commit configuration to a top-level map. '
|
|
||||||
'support for top level list will be removed in a future version. '
|
|
||||||
'run: `pre-commit migrate-config` to automatically fix this.',
|
|
||||||
)
|
|
||||||
return {'repos': data}
|
|
||||||
else:
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
load_config = functools.partial(
|
load_config = functools.partial(
|
||||||
cfgv.load_from_filename,
|
cfgv.load_from_filename,
|
||||||
schema=CONFIG_SCHEMA,
|
schema=CONFIG_SCHEMA,
|
||||||
load_strategy=ordered_load_normalize_legacy_config,
|
load_strategy=yaml_load,
|
||||||
exc_tp=InvalidConfigError,
|
exc_tp=InvalidConfigError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,14 +120,6 @@ def test_validate_config_main_ok():
|
||||||
assert not validate_config_main(('.pre-commit-config.yaml',))
|
assert not validate_config_main(('.pre-commit-config.yaml',))
|
||||||
|
|
||||||
|
|
||||||
def test_validate_config_old_list_format_ok(tmpdir, cap_out):
|
|
||||||
f = tmpdir.join('cfg.yaml')
|
|
||||||
f.write('- {repo: meta, hooks: [{id: identity}]}')
|
|
||||||
assert not validate_config_main((f.strpath,))
|
|
||||||
msg = '[WARNING] normalizing pre-commit configuration to a top-level map'
|
|
||||||
assert msg in cap_out.get()
|
|
||||||
|
|
||||||
|
|
||||||
def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
|
def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
|
||||||
f = tmpdir.join('cfg.yaml')
|
f = tmpdir.join('cfg.yaml')
|
||||||
f.write(
|
f.write(
|
||||||
|
|
|
||||||
|
|
@ -739,7 +739,8 @@ def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store):
|
||||||
|
|
||||||
def test_post_commit_integration(tempdir_factory, store):
|
def test_post_commit_integration(tempdir_factory, store):
|
||||||
path = git_dir(tempdir_factory)
|
path = git_dir(tempdir_factory)
|
||||||
config = [
|
config = {
|
||||||
|
'repos': [
|
||||||
{
|
{
|
||||||
'repo': 'local',
|
'repo': 'local',
|
||||||
'hooks': [{
|
'hooks': [{
|
||||||
|
|
@ -752,7 +753,8 @@ def test_post_commit_integration(tempdir_factory, store):
|
||||||
'stages': ['post-commit'],
|
'stages': ['post-commit'],
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
|
}
|
||||||
write_config(path, config)
|
write_config(path, config)
|
||||||
with cwd(path):
|
with cwd(path):
|
||||||
_get_commit_output(tempdir_factory)
|
_get_commit_output(tempdir_factory)
|
||||||
|
|
@ -765,7 +767,8 @@ def test_post_commit_integration(tempdir_factory, store):
|
||||||
|
|
||||||
def test_post_merge_integration(tempdir_factory, store):
|
def test_post_merge_integration(tempdir_factory, store):
|
||||||
path = git_dir(tempdir_factory)
|
path = git_dir(tempdir_factory)
|
||||||
config = [
|
config = {
|
||||||
|
'repos': [
|
||||||
{
|
{
|
||||||
'repo': 'local',
|
'repo': 'local',
|
||||||
'hooks': [{
|
'hooks': [{
|
||||||
|
|
@ -778,7 +781,8 @@ def test_post_merge_integration(tempdir_factory, store):
|
||||||
'stages': ['post-merge'],
|
'stages': ['post-merge'],
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
|
}
|
||||||
write_config(path, config)
|
write_config(path, config)
|
||||||
with cwd(path):
|
with cwd(path):
|
||||||
# create a simple diamond of commits for a non-trivial merge
|
# create a simple diamond of commits for a non-trivial merge
|
||||||
|
|
@ -807,7 +811,8 @@ def test_post_merge_integration(tempdir_factory, store):
|
||||||
|
|
||||||
def test_post_rewrite_integration(tempdir_factory, store):
|
def test_post_rewrite_integration(tempdir_factory, store):
|
||||||
path = git_dir(tempdir_factory)
|
path = git_dir(tempdir_factory)
|
||||||
config = [
|
config = {
|
||||||
|
'repos': [
|
||||||
{
|
{
|
||||||
'repo': 'local',
|
'repo': 'local',
|
||||||
'hooks': [{
|
'hooks': [{
|
||||||
|
|
@ -820,7 +825,8 @@ def test_post_rewrite_integration(tempdir_factory, store):
|
||||||
'stages': ['post-rewrite'],
|
'stages': ['post-rewrite'],
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
|
}
|
||||||
write_config(path, config)
|
write_config(path, config)
|
||||||
with cwd(path):
|
with cwd(path):
|
||||||
open('init', 'a').close()
|
open('init', 'a').close()
|
||||||
|
|
@ -836,7 +842,8 @@ def test_post_rewrite_integration(tempdir_factory, store):
|
||||||
|
|
||||||
def test_post_checkout_integration(tempdir_factory, store):
|
def test_post_checkout_integration(tempdir_factory, store):
|
||||||
path = git_dir(tempdir_factory)
|
path = git_dir(tempdir_factory)
|
||||||
config = [
|
config = {
|
||||||
|
'repos': [
|
||||||
{
|
{
|
||||||
'repo': 'local',
|
'repo': 'local',
|
||||||
'hooks': [{
|
'hooks': [{
|
||||||
|
|
@ -850,7 +857,8 @@ def test_post_checkout_integration(tempdir_factory, store):
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
{'repo': 'meta', 'hooks': [{'id': 'identity'}]},
|
{'repo': 'meta', 'hooks': [{'id': 'identity'}]},
|
||||||
]
|
],
|
||||||
|
}
|
||||||
write_config(path, config)
|
write_config(path, config)
|
||||||
with cwd(path):
|
with cwd(path):
|
||||||
cmd_output('git', 'add', '.')
|
cmd_output('git', 'add', '.')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue