File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change 22
33import yaml
44
5+ from pre_commit .clientlib import load_config
56from pre_commit .util import yaml_load
67
78
@@ -43,6 +44,9 @@ def _migrate_sha_to_rev(contents: str) -> str:
4344
4445
4546def migrate_config (config_file : str , quiet : bool = False ) -> int :
47+ # ensure that the configuration is a valid pre-commit configuration
48+ load_config (config_file )
49+
4650 with open (config_file ) as f :
4751 orig_contents = contents = f .read ()
4852
Original file line number Diff line number Diff line change 11import pytest
22
33import pre_commit .constants as C
4+ from pre_commit .clientlib import InvalidConfigError
45from pre_commit .commands .migrate_config import _indent
56from pre_commit .commands .migrate_config import migrate_config
67
@@ -147,10 +148,10 @@ def test_migrate_config_sha_to_rev(tmpdir):
147148
148149
149150@pytest .mark .parametrize ('contents' , ('' , '\n ' ))
150- def test_empty_configuration_file_user_error (tmpdir , contents ):
151+ def test_migrate_config_invalid_configuration (tmpdir , contents ):
151152 cfg = tmpdir .join (C .CONFIG_FILE )
152153 cfg .write (contents )
153- with tmpdir .as_cwd ():
154- assert not migrate_config (C .CONFIG_FILE )
154+ with tmpdir .as_cwd (), pytest . raises ( InvalidConfigError ) :
155+ migrate_config (C .CONFIG_FILE )
155156 # even though the config is invalid, this should be a noop
156157 assert cfg .read () == contents
You can’t perform that action at this time.
0 commit comments