Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff3150d

Browse files
committed
remove support for sha to specify rev
1 parent 40c5bda commit ff3150d

2 files changed

Lines changed: 5 additions & 82 deletions

File tree

pre_commit/clientlib.py

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ def validate_manifest_main(argv: Sequence[str] | None = None) -> int:
114114
META = 'meta'
115115

116116

117-
# should inherit from cfgv.Conditional if sha support is dropped
118-
class WarnMutableRev(cfgv.ConditionalOptional):
117+
class WarnMutableRev(cfgv.Conditional):
119118
def check(self, dct: dict[str, Any]) -> None:
120119
super().check(dct)
121120

@@ -171,36 +170,6 @@ def check(self, dct: dict[str, Any]) -> None:
171170
)
172171

173172

174-
class MigrateShaToRev:
175-
key = 'rev'
176-
177-
@staticmethod
178-
def _cond(key: str) -> cfgv.Conditional:
179-
return cfgv.Conditional(
180-
key, cfgv.check_string,
181-
condition_key='repo',
182-
condition_value=cfgv.NotIn(LOCAL, META),
183-
ensure_absent=True,
184-
)
185-
186-
def check(self, dct: dict[str, Any]) -> None:
187-
if dct.get('repo') in {LOCAL, META}:
188-
self._cond('rev').check(dct)
189-
self._cond('sha').check(dct)
190-
elif 'sha' in dct and 'rev' in dct:
191-
raise cfgv.ValidationError('Cannot specify both sha and rev')
192-
elif 'sha' in dct:
193-
self._cond('sha').check(dct)
194-
else:
195-
self._cond('rev').check(dct)
196-
197-
def apply_default(self, dct: dict[str, Any]) -> None:
198-
if 'sha' in dct:
199-
dct['rev'] = dct.pop('sha')
200-
201-
remove_default = cfgv.Required.remove_default
202-
203-
204173
def _entry(modname: str) -> str:
205174
"""the hook `entry` is passed through `shlex.split()` by the command
206175
runner, so to prevent issues with spaces and backslashes (on Windows)
@@ -324,14 +293,11 @@ def check(self, dct: dict[str, Any]) -> None:
324293
'repo', META,
325294
),
326295

327-
MigrateShaToRev(),
328296
WarnMutableRev(
329-
'rev',
330-
cfgv.check_string,
331-
'',
332-
'repo',
333-
cfgv.NotIn(LOCAL, META),
334-
True,
297+
'rev', cfgv.check_string,
298+
condition_key='repo',
299+
condition_value=cfgv.NotIn(LOCAL, META),
300+
ensure_absent=True,
335301
),
336302
cfgv.WarnAdditionalKeys(('repo', 'rev', 'hooks'), warn_unknown_keys_repo),
337303
)

tests/clientlib_test.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from pre_commit.clientlib import DEFAULT_LANGUAGE_VERSION
1515
from pre_commit.clientlib import MANIFEST_SCHEMA
1616
from pre_commit.clientlib import META_HOOK_DICT
17-
from pre_commit.clientlib import MigrateShaToRev
1817
from pre_commit.clientlib import OptionalSensibleRegexAtHook
1918
from pre_commit.clientlib import OptionalSensibleRegexAtTop
2019
from pre_commit.clientlib import validate_config_main
@@ -425,48 +424,6 @@ def test_valid_manifests(manifest_obj, expected):
425424
assert ret is expected
426425

427426

428-
@pytest.mark.parametrize(
429-
'dct',
430-
(
431-
{'repo': 'local'}, {'repo': 'meta'},
432-
{'repo': 'wat', 'sha': 'wat'}, {'repo': 'wat', 'rev': 'wat'},
433-
),
434-
)
435-
def test_migrate_sha_to_rev_ok(dct):
436-
MigrateShaToRev().check(dct)
437-
438-
439-
def test_migrate_sha_to_rev_dont_specify_both():
440-
with pytest.raises(cfgv.ValidationError) as excinfo:
441-
MigrateShaToRev().check({'repo': 'a', 'sha': 'b', 'rev': 'c'})
442-
msg, = excinfo.value.args
443-
assert msg == 'Cannot specify both sha and rev'
444-
445-
446-
@pytest.mark.parametrize(
447-
'dct',
448-
(
449-
{'repo': 'a'},
450-
{'repo': 'meta', 'sha': 'a'}, {'repo': 'meta', 'rev': 'a'},
451-
),
452-
)
453-
def test_migrate_sha_to_rev_conditional_check_failures(dct):
454-
with pytest.raises(cfgv.ValidationError):
455-
MigrateShaToRev().check(dct)
456-
457-
458-
def test_migrate_to_sha_apply_default():
459-
dct = {'repo': 'a', 'sha': 'b'}
460-
MigrateShaToRev().apply_default(dct)
461-
assert dct == {'repo': 'a', 'rev': 'b'}
462-
463-
464-
def test_migrate_to_sha_ok():
465-
dct = {'repo': 'a', 'rev': 'b'}
466-
MigrateShaToRev().apply_default(dct)
467-
assert dct == {'repo': 'a', 'rev': 'b'}
468-
469-
470427
@pytest.mark.parametrize(
471428
'config_repo',
472429
(

0 commit comments

Comments
 (0)