remove support for sha to specify rev

This commit is contained in:
Anthony Sottile
2022-12-27 11:29:00 -05:00
parent 40c5bdad65
commit ff3150d58a
2 changed files with 5 additions and 82 deletions

View File

@@ -114,8 +114,7 @@ LOCAL = 'local'
META = 'meta'
# should inherit from cfgv.Conditional if sha support is dropped
class WarnMutableRev(cfgv.ConditionalOptional):
class WarnMutableRev(cfgv.Conditional):
def check(self, dct: dict[str, Any]) -> None:
super().check(dct)
@@ -171,36 +170,6 @@ class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault):
)
class MigrateShaToRev:
key = 'rev'
@staticmethod
def _cond(key: str) -> cfgv.Conditional:
return cfgv.Conditional(
key, cfgv.check_string,
condition_key='repo',
condition_value=cfgv.NotIn(LOCAL, META),
ensure_absent=True,
)
def check(self, dct: dict[str, Any]) -> None:
if dct.get('repo') in {LOCAL, META}:
self._cond('rev').check(dct)
self._cond('sha').check(dct)
elif 'sha' in dct and 'rev' in dct:
raise cfgv.ValidationError('Cannot specify both sha and rev')
elif 'sha' in dct:
self._cond('sha').check(dct)
else:
self._cond('rev').check(dct)
def apply_default(self, dct: dict[str, Any]) -> None:
if 'sha' in dct:
dct['rev'] = dct.pop('sha')
remove_default = cfgv.Required.remove_default
def _entry(modname: str) -> str:
"""the hook `entry` is passed through `shlex.split()` by the command
runner, so to prevent issues with spaces and backslashes (on Windows)
@@ -324,14 +293,11 @@ CONFIG_REPO_DICT = cfgv.Map(
'repo', META,
),
MigrateShaToRev(),
WarnMutableRev(
'rev',
cfgv.check_string,
'',
'repo',
cfgv.NotIn(LOCAL, META),
True,
'rev', cfgv.check_string,
condition_key='repo',
condition_value=cfgv.NotIn(LOCAL, META),
ensure_absent=True,
),
cfgv.WarnAdditionalKeys(('repo', 'rev', 'hooks'), warn_unknown_keys_repo),
)

View File

@@ -14,7 +14,6 @@ from pre_commit.clientlib import CONFIG_SCHEMA
from pre_commit.clientlib import DEFAULT_LANGUAGE_VERSION
from pre_commit.clientlib import MANIFEST_SCHEMA
from pre_commit.clientlib import META_HOOK_DICT
from pre_commit.clientlib import MigrateShaToRev
from pre_commit.clientlib import OptionalSensibleRegexAtHook
from pre_commit.clientlib import OptionalSensibleRegexAtTop
from pre_commit.clientlib import validate_config_main
@@ -425,48 +424,6 @@ def test_valid_manifests(manifest_obj, expected):
assert ret is expected
@pytest.mark.parametrize(
'dct',
(
{'repo': 'local'}, {'repo': 'meta'},
{'repo': 'wat', 'sha': 'wat'}, {'repo': 'wat', 'rev': 'wat'},
),
)
def test_migrate_sha_to_rev_ok(dct):
MigrateShaToRev().check(dct)
def test_migrate_sha_to_rev_dont_specify_both():
with pytest.raises(cfgv.ValidationError) as excinfo:
MigrateShaToRev().check({'repo': 'a', 'sha': 'b', 'rev': 'c'})
msg, = excinfo.value.args
assert msg == 'Cannot specify both sha and rev'
@pytest.mark.parametrize(
'dct',
(
{'repo': 'a'},
{'repo': 'meta', 'sha': 'a'}, {'repo': 'meta', 'rev': 'a'},
),
)
def test_migrate_sha_to_rev_conditional_check_failures(dct):
with pytest.raises(cfgv.ValidationError):
MigrateShaToRev().check(dct)
def test_migrate_to_sha_apply_default():
dct = {'repo': 'a', 'sha': 'b'}
MigrateShaToRev().apply_default(dct)
assert dct == {'repo': 'a', 'rev': 'b'}
def test_migrate_to_sha_ok():
dct = {'repo': 'a', 'rev': 'b'}
MigrateShaToRev().apply_default(dct)
assert dct == {'repo': 'a', 'rev': 'b'}
@pytest.mark.parametrize(
'config_repo',
(