mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-15 13:30:17 -06:00
added warning if mutable rev is used
This commit is contained in:
committed by
Anthony Sottile
parent
8670d0b3bc
commit
1e4de986a8
@@ -1,6 +1,7 @@
|
||||
import argparse
|
||||
import functools
|
||||
import logging
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
from typing import Any
|
||||
@@ -112,6 +113,25 @@ LOCAL = 'local'
|
||||
META = 'meta'
|
||||
|
||||
|
||||
# should inherit from cfgv.Conditional if sha support is dropped
|
||||
class WarnMutableRev(cfgv.ConditionalOptional):
|
||||
def check(self, dct: Dict[str, Any]) -> None:
|
||||
super().check(dct)
|
||||
|
||||
if self.key in dct:
|
||||
rev = dct[self.key]
|
||||
|
||||
if '.' not in rev and not re.match(r'^[a-fA-F0-9]+$', rev):
|
||||
logger.warning(
|
||||
f'The {self.key!r} field of repo {dct["repo"]!r} '
|
||||
f'appears to be a mutable reference '
|
||||
f'(moving tag / branch). Mutable references are never '
|
||||
f'updated after first install and are not supported. '
|
||||
f'See https://pre-commit.com/#using-the-latest-version-for-a-repository ' # noqa: E501
|
||||
f'for more details.',
|
||||
)
|
||||
|
||||
|
||||
class OptionalSensibleRegex(cfgv.OptionalNoDefault):
|
||||
def check(self, dct: Dict[str, Any]) -> None:
|
||||
super().check(dct)
|
||||
@@ -261,6 +281,14 @@ CONFIG_REPO_DICT = cfgv.Map(
|
||||
),
|
||||
|
||||
MigrateShaToRev(),
|
||||
WarnMutableRev(
|
||||
'rev',
|
||||
cfgv.check_string,
|
||||
'',
|
||||
'repo',
|
||||
cfgv.NotIn(LOCAL, META),
|
||||
True,
|
||||
),
|
||||
cfgv.WarnAdditionalKeys(('repo', 'rev', 'hooks'), warn_unknown_keys_repo),
|
||||
)
|
||||
DEFAULT_LANGUAGE_VERSION = cfgv.Map(
|
||||
|
||||
Reference in New Issue
Block a user