mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
Fix precommit issues
This commit is contained in:
parent
189490a938
commit
0d40562dcb
4 changed files with 35 additions and 15 deletions
|
|
@ -100,6 +100,7 @@ def _ns(
|
|||
rewrite_command=rewrite_command,
|
||||
files=(),
|
||||
hook=None,
|
||||
tags=(),
|
||||
verbose=False,
|
||||
show_diff_on_failure=False,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import time
|
|||
import unicodedata
|
||||
from typing import Any
|
||||
from typing import Collection
|
||||
from typing import Iterable
|
||||
from typing import MutableMapping
|
||||
from typing import Sequence
|
||||
|
||||
|
|
@ -323,26 +324,29 @@ def _has_unstaged_config(config_file: str) -> bool:
|
|||
# be explicit, other git errors don't mean it has an unstaged config.
|
||||
return retcode == 1
|
||||
|
||||
|
||||
def _hook_should_run(args: argparse.Namespace, hook: Hook) -> bool:
|
||||
if args.hook_stage not in hook.stages:
|
||||
return False
|
||||
|
||||
if args.tags:
|
||||
return len(set(hook.tags) & set(args.tags)) > 0
|
||||
|
||||
|
||||
return (
|
||||
not args.hook
|
||||
or hook.id == args.hook
|
||||
or hook.alias == args.hook
|
||||
not args.hook or
|
||||
hook.id == args.hook or
|
||||
hook.alias == args.hook
|
||||
)
|
||||
|
||||
def _hook_is_skipped(skips: Sequence[str], hook: Hook) -> bool:
|
||||
|
||||
def _hook_is_skipped(skips: Iterable[str], hook: Hook) -> bool:
|
||||
return (
|
||||
hook.id in skips
|
||||
or hook.alias in skips
|
||||
or len(set(hook.tags) & set(skips)) > 0
|
||||
hook.id in skips or
|
||||
hook.alias in skips or
|
||||
len(set(hook.tags) & set(skips)) > 0
|
||||
)
|
||||
|
||||
|
||||
def run(
|
||||
config_file: str,
|
||||
store: Store,
|
||||
|
|
@ -438,7 +442,8 @@ def run(
|
|||
return 1
|
||||
if args.tags and not hooks:
|
||||
output.write_line(
|
||||
f'No hooks with tags matching `{args.tags}` in stage `{args.hook_stage}`'
|
||||
f'No hooks with tags matching `{args.tags}` '
|
||||
f'in stage `{args.hook_stage}`',
|
||||
)
|
||||
return 1
|
||||
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@
|
|||
language: script
|
||||
files: ''
|
||||
tags:
|
||||
- foo
|
||||
- foo
|
||||
|
|
|
|||
|
|
@ -144,14 +144,21 @@ def _do_run(cap_out, store, repo, args, environ={}, config_file=C.CONFIG_FILE):
|
|||
|
||||
def _test_run(
|
||||
cap_out, store, repo, opts, expected_outputs, expected_ret, stage,
|
||||
config_file=C.CONFIG_FILE, environ_override=None
|
||||
config_file=C.CONFIG_FILE, environ_override=None,
|
||||
):
|
||||
if stage:
|
||||
stage_a_file()
|
||||
if environ_override is None:
|
||||
environ_override = {}
|
||||
args = run_opts(**opts)
|
||||
ret, printed = _do_run(cap_out, store, repo, args, config_file=config_file, environ=environ_override)
|
||||
ret, printed = _do_run(
|
||||
cap_out,
|
||||
store,
|
||||
repo,
|
||||
args,
|
||||
config_file=config_file,
|
||||
environ=environ_override,
|
||||
)
|
||||
|
||||
assert ret == expected_ret, (ret, expected_ret, printed)
|
||||
for expected_output_part in expected_outputs:
|
||||
|
|
@ -369,13 +376,19 @@ def test_show_diff_on_failure(
|
|||
),
|
||||
(
|
||||
{'tags': ['bar', 'baz']},
|
||||
(b'No hooks with tags matching `[\'bar\', \'baz\']` in stage `commit`',),
|
||||
(
|
||||
b'No hooks with tags matching `[\'bar\', \'baz\']`',
|
||||
b'in stage `commit`',
|
||||
),
|
||||
1,
|
||||
True,
|
||||
),
|
||||
(
|
||||
{'tags': ['bar', 'baz'], 'hook_stage': 'push'},
|
||||
(b'No hooks with tags matching `[\'bar\', \'baz\']` in stage `push`',),
|
||||
(
|
||||
b'No hooks with tags matching `[\'bar\', \'baz\']`',
|
||||
b'in stage `push`',
|
||||
),
|
||||
1,
|
||||
True,
|
||||
),
|
||||
|
|
@ -633,6 +646,7 @@ def test_skip_aliased_hook(cap_out, store, aliased_repo):
|
|||
for msg in (b'Bash hook', b'Skipped'):
|
||||
assert printed.count(msg) == 1
|
||||
|
||||
|
||||
def test_skip_tag(cap_out, store, repo_with_passing_hook):
|
||||
_test_run(
|
||||
cap_out,
|
||||
|
|
@ -642,7 +656,7 @@ def test_skip_tag(cap_out, store, repo_with_passing_hook):
|
|||
(b'Bash hook', b'Skipped'),
|
||||
0,
|
||||
True,
|
||||
environ_override={'SKIP': 'foo'}
|
||||
environ_override={'SKIP': 'foo'},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue