Skip to content

Commit 0024484

Browse files
committed
remove support for top-level list format
1 parent 40c5bda commit 0024484

File tree

3 files changed

+66
-79
lines changed

3 files changed

+66
-79
lines changed

pre_commit/clientlib.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -391,23 +391,10 @@ class InvalidConfigError(FatalError):
391391
pass
392392

393393

394-
def ordered_load_normalize_legacy_config(contents: str) -> dict[str, Any]:
395-
data = yaml_load(contents)
396-
if isinstance(data, list):
397-
logger.warning(
398-
'normalizing pre-commit configuration to a top-level map. '
399-
'support for top level list will be removed in a future version. '
400-
'run: `pre-commit migrate-config` to automatically fix this.',
401-
)
402-
return {'repos': data}
403-
else:
404-
return data
405-
406-
407394
load_config = functools.partial(
408395
cfgv.load_from_filename,
409396
schema=CONFIG_SCHEMA,
410-
load_strategy=ordered_load_normalize_legacy_config,
397+
load_strategy=yaml_load,
411398
exc_tp=InvalidConfigError,
412399
)
413400

tests/clientlib_test.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ def test_validate_config_main_ok():
120120
assert not validate_config_main(('.pre-commit-config.yaml',))
121121

122122

123-
def test_validate_config_old_list_format_ok(tmpdir, cap_out):
124-
f = tmpdir.join('cfg.yaml')
125-
f.write('- {repo: meta, hooks: [{id: identity}]}')
126-
assert not validate_config_main((f.strpath,))
127-
msg = '[WARNING] normalizing pre-commit configuration to a top-level map'
128-
assert msg in cap_out.get()
129-
130-
131123
def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
132124
f = tmpdir.join('cfg.yaml')
133125
f.write(

tests/commands/install_uninstall_test.py

Lines changed: 65 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -739,20 +739,22 @@ def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store):
739739

740740
def test_post_commit_integration(tempdir_factory, store):
741741
path = git_dir(tempdir_factory)
742-
config = [
743-
{
744-
'repo': 'local',
745-
'hooks': [{
746-
'id': 'post-commit',
747-
'name': 'Post commit',
748-
'entry': 'touch post-commit.tmp',
749-
'language': 'system',
750-
'always_run': True,
751-
'verbose': True,
752-
'stages': ['post-commit'],
753-
}],
754-
},
755-
]
742+
config = {
743+
'repos': [
744+
{
745+
'repo': 'local',
746+
'hooks': [{
747+
'id': 'post-commit',
748+
'name': 'Post commit',
749+
'entry': 'touch post-commit.tmp',
750+
'language': 'system',
751+
'always_run': True,
752+
'verbose': True,
753+
'stages': ['post-commit'],
754+
}],
755+
},
756+
],
757+
}
756758
write_config(path, config)
757759
with cwd(path):
758760
_get_commit_output(tempdir_factory)
@@ -765,20 +767,22 @@ def test_post_commit_integration(tempdir_factory, store):
765767

766768
def test_post_merge_integration(tempdir_factory, store):
767769
path = git_dir(tempdir_factory)
768-
config = [
769-
{
770-
'repo': 'local',
771-
'hooks': [{
772-
'id': 'post-merge',
773-
'name': 'Post merge',
774-
'entry': 'touch post-merge.tmp',
775-
'language': 'system',
776-
'always_run': True,
777-
'verbose': True,
778-
'stages': ['post-merge'],
779-
}],
780-
},
781-
]
770+
config = {
771+
'repos': [
772+
{
773+
'repo': 'local',
774+
'hooks': [{
775+
'id': 'post-merge',
776+
'name': 'Post merge',
777+
'entry': 'touch post-merge.tmp',
778+
'language': 'system',
779+
'always_run': True,
780+
'verbose': True,
781+
'stages': ['post-merge'],
782+
}],
783+
},
784+
],
785+
}
782786
write_config(path, config)
783787
with cwd(path):
784788
# create a simple diamond of commits for a non-trivial merge
@@ -807,20 +811,22 @@ def test_post_merge_integration(tempdir_factory, store):
807811

808812
def test_post_rewrite_integration(tempdir_factory, store):
809813
path = git_dir(tempdir_factory)
810-
config = [
811-
{
812-
'repo': 'local',
813-
'hooks': [{
814-
'id': 'post-rewrite',
815-
'name': 'Post rewrite',
816-
'entry': 'touch post-rewrite.tmp',
817-
'language': 'system',
818-
'always_run': True,
819-
'verbose': True,
820-
'stages': ['post-rewrite'],
821-
}],
822-
},
823-
]
814+
config = {
815+
'repos': [
816+
{
817+
'repo': 'local',
818+
'hooks': [{
819+
'id': 'post-rewrite',
820+
'name': 'Post rewrite',
821+
'entry': 'touch post-rewrite.tmp',
822+
'language': 'system',
823+
'always_run': True,
824+
'verbose': True,
825+
'stages': ['post-rewrite'],
826+
}],
827+
},
828+
],
829+
}
824830
write_config(path, config)
825831
with cwd(path):
826832
open('init', 'a').close()
@@ -836,21 +842,23 @@ def test_post_rewrite_integration(tempdir_factory, store):
836842

837843
def test_post_checkout_integration(tempdir_factory, store):
838844
path = git_dir(tempdir_factory)
839-
config = [
840-
{
841-
'repo': 'local',
842-
'hooks': [{
843-
'id': 'post-checkout',
844-
'name': 'Post checkout',
845-
'entry': 'bash -c "echo ${PRE_COMMIT_TO_REF}"',
846-
'language': 'system',
847-
'always_run': True,
848-
'verbose': True,
849-
'stages': ['post-checkout'],
850-
}],
851-
},
852-
{'repo': 'meta', 'hooks': [{'id': 'identity'}]},
853-
]
845+
config = {
846+
'repos': [
847+
{
848+
'repo': 'local',
849+
'hooks': [{
850+
'id': 'post-checkout',
851+
'name': 'Post checkout',
852+
'entry': 'bash -c "echo ${PRE_COMMIT_TO_REF}"',
853+
'language': 'system',
854+
'always_run': True,
855+
'verbose': True,
856+
'stages': ['post-checkout'],
857+
}],
858+
},
859+
{'repo': 'meta', 'hooks': [{'id': 'identity'}]},
860+
],
861+
}
854862
write_config(path, config)
855863
with cwd(path):
856864
cmd_output('git', 'add', '.')

0 commit comments

Comments
 (0)