Adding upstream version 2.10.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
5f54aad01b
commit
b51ea48cbd
17 changed files with 286 additions and 39 deletions
|
@ -1,6 +1,7 @@
|
|||
import argparse
|
||||
import functools
|
||||
import logging
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
from typing import Any
|
||||
|
@ -112,7 +113,26 @@ LOCAL = 'local'
|
|||
META = 'meta'
|
||||
|
||||
|
||||
class OptionalSensibleRegex(cfgv.OptionalNoDefault):
|
||||
# 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 OptionalSensibleRegexAtHook(cfgv.OptionalNoDefault):
|
||||
def check(self, dct: Dict[str, Any]) -> None:
|
||||
super().check(dct)
|
||||
|
||||
|
@ -124,6 +144,17 @@ class OptionalSensibleRegex(cfgv.OptionalNoDefault):
|
|||
)
|
||||
|
||||
|
||||
class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault):
|
||||
def check(self, dct: Dict[str, Any]) -> None:
|
||||
super().check(dct)
|
||||
|
||||
if '/*' in dct.get(self.key, ''):
|
||||
logger.warning(
|
||||
f'The top-level {self.key!r} field is a regex, not a glob -- '
|
||||
f"matching '/*' probably isn't what you want here",
|
||||
)
|
||||
|
||||
|
||||
class MigrateShaToRev:
|
||||
key = 'rev'
|
||||
|
||||
|
@ -239,8 +270,8 @@ CONFIG_HOOK_DICT = cfgv.Map(
|
|||
for item in MANIFEST_HOOK_DICT.items
|
||||
if item.key != 'id'
|
||||
),
|
||||
OptionalSensibleRegex('files', cfgv.check_string),
|
||||
OptionalSensibleRegex('exclude', cfgv.check_string),
|
||||
OptionalSensibleRegexAtHook('files', cfgv.check_string),
|
||||
OptionalSensibleRegexAtHook('exclude', cfgv.check_string),
|
||||
)
|
||||
CONFIG_REPO_DICT = cfgv.Map(
|
||||
'Repository', 'repo',
|
||||
|
@ -261,6 +292,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(
|
||||
|
@ -297,9 +336,15 @@ CONFIG_SCHEMA = cfgv.Map(
|
|||
'exclude',
|
||||
'fail_fast',
|
||||
'minimum_pre_commit_version',
|
||||
'ci',
|
||||
),
|
||||
warn_unknown_keys_root,
|
||||
),
|
||||
OptionalSensibleRegexAtTop('files', cfgv.check_string),
|
||||
OptionalSensibleRegexAtTop('exclude', cfgv.check_string),
|
||||
|
||||
# do not warn about configuration for pre-commit.ci
|
||||
cfgv.OptionalNoDefault('ci', cfgv.check_type(dict)),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ def _ns(
|
|||
color: bool,
|
||||
*,
|
||||
all_files: bool = False,
|
||||
remote_branch: Optional[str] = None,
|
||||
from_ref: Optional[str] = None,
|
||||
to_ref: Optional[str] = None,
|
||||
remote_name: Optional[str] = None,
|
||||
|
@ -79,6 +80,7 @@ def _ns(
|
|||
return argparse.Namespace(
|
||||
color=color,
|
||||
hook_stage=hook_type.replace('pre-', ''),
|
||||
remote_branch=remote_branch,
|
||||
from_ref=from_ref,
|
||||
to_ref=to_ref,
|
||||
remote_name=remote_name,
|
||||
|
@ -106,13 +108,14 @@ def _pre_push_ns(
|
|||
remote_url = args[1]
|
||||
|
||||
for line in stdin.decode().splitlines():
|
||||
_, local_sha, _, remote_sha = line.split()
|
||||
_, local_sha, remote_branch, remote_sha = line.split()
|
||||
if local_sha == Z40:
|
||||
continue
|
||||
elif remote_sha != Z40 and _rev_exists(remote_sha):
|
||||
return _ns(
|
||||
'pre-push', color,
|
||||
from_ref=remote_sha, to_ref=local_sha,
|
||||
remote_branch=remote_branch,
|
||||
remote_name=remote_name, remote_url=remote_url,
|
||||
)
|
||||
else:
|
||||
|
@ -133,6 +136,7 @@ def _pre_push_ns(
|
|||
'pre-push', color,
|
||||
all_files=True,
|
||||
remote_name=remote_name, remote_url=remote_url,
|
||||
remote_branch=remote_branch,
|
||||
)
|
||||
else:
|
||||
rev_cmd = ('git', 'rev-parse', f'{first_ancestor}^')
|
||||
|
@ -141,6 +145,7 @@ def _pre_push_ns(
|
|||
'pre-push', color,
|
||||
from_ref=source, to_ref=local_sha,
|
||||
remote_name=remote_name, remote_url=remote_url,
|
||||
remote_branch=remote_branch,
|
||||
)
|
||||
|
||||
# nothing to push
|
||||
|
|
|
@ -371,7 +371,8 @@ def run(
|
|||
environ['PRE_COMMIT_FROM_REF'] = args.from_ref
|
||||
environ['PRE_COMMIT_TO_REF'] = args.to_ref
|
||||
|
||||
if args.remote_name and args.remote_url:
|
||||
if args.remote_name and args.remote_url and args.remote_branch:
|
||||
environ['PRE_COMMIT_REMOTE_BRANCH'] = args.remote_branch
|
||||
environ['PRE_COMMIT_REMOTE_NAME'] = args.remote_name
|
||||
environ['PRE_COMMIT_REMOTE_URL'] = args.remote_url
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import contextlib
|
||||
import errno
|
||||
import os
|
||||
import sys
|
||||
from typing import Callable
|
||||
from typing import Generator
|
||||
|
||||
|
||||
if os.name == 'nt': # pragma: no cover (windows)
|
||||
if sys.platform == 'win32': # pragma: no cover (windows)
|
||||
import msvcrt
|
||||
|
||||
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/locking
|
||||
|
|
|
@ -61,7 +61,7 @@ def get_root() -> str:
|
|||
'git failed. Is it installed, and are you in a Git repository '
|
||||
'directory?',
|
||||
)
|
||||
if os.path.commonpath((root, git_dir)) == git_dir:
|
||||
if os.path.samefile(root, git_dir):
|
||||
raise FatalError(
|
||||
'git toplevel unexpectedly empty! make sure you are not '
|
||||
'inside the `.git` directory of your repository.',
|
||||
|
|
|
@ -96,6 +96,9 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
|||
'--hook-stage', choices=C.STAGES, default='commit',
|
||||
help='The stage during which the hook is fired. One of %(choices)s',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--remote-branch', help='Remote branch ref used by `git push`.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--from-ref', '--source', '-s',
|
||||
help=(
|
||||
|
|
|
@ -118,6 +118,24 @@ def _hook(
|
|||
if not ret['stages']:
|
||||
ret['stages'] = root_config['default_stages']
|
||||
|
||||
if languages[lang].ENVIRONMENT_DIR is None:
|
||||
if ret['language_version'] != C.DEFAULT:
|
||||
logger.error(
|
||||
f'The hook `{ret["id"]}` specifies `language_version` but is '
|
||||
f'using language `{lang}` which does not install an '
|
||||
f'environment. '
|
||||
f'Perhaps you meant to use a specific language?',
|
||||
)
|
||||
exit(1)
|
||||
if ret['additional_dependencies']:
|
||||
logger.error(
|
||||
f'The hook `{ret["id"]}` specifies `additional_dependencies` '
|
||||
f'but is using language `{lang}` which does not install an '
|
||||
f'environment. '
|
||||
f'Perhaps you meant to use a specific language?',
|
||||
)
|
||||
exit(1)
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue