mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Implement default_stages
This commit is contained in:
parent
9c6a1d80d6
commit
bd65d8947f
4 changed files with 29 additions and 3 deletions
|
|
@ -224,6 +224,11 @@ CONFIG_SCHEMA = cfgv.Map(
|
||||||
cfgv.OptionalRecurse(
|
cfgv.OptionalRecurse(
|
||||||
'default_language_version', DEFAULT_LANGUAGE_VERSION, {},
|
'default_language_version', DEFAULT_LANGUAGE_VERSION, {},
|
||||||
),
|
),
|
||||||
|
cfgv.Optional(
|
||||||
|
'default_stages',
|
||||||
|
cfgv.check_array(cfgv.check_one_of(C.STAGES)),
|
||||||
|
C.STAGES,
|
||||||
|
),
|
||||||
cfgv.Optional('exclude', cfgv.check_regex, '^$'),
|
cfgv.Optional('exclude', cfgv.check_regex, '^$'),
|
||||||
cfgv.Optional('fail_fast', cfgv.check_bool, False),
|
cfgv.Optional('fail_fast', cfgv.check_bool, False),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ def run(config_file, store, args, environ=os.environ):
|
||||||
hook
|
hook
|
||||||
for hook in all_hooks(config, store)
|
for hook in all_hooks(config, store)
|
||||||
if not args.hook or hook.id == args.hook or hook.alias == args.hook
|
if not args.hook or hook.id == args.hook or hook.alias == args.hook
|
||||||
if not hook.stages or args.hook_stage in hook.stages
|
if args.hook_stage in hook.stages
|
||||||
]
|
]
|
||||||
|
|
||||||
if args.hook and not hooks:
|
if args.hook and not hooks:
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,9 @@ def _hook(*hook_dicts, **kwargs):
|
||||||
if ret['language_version'] == C.DEFAULT:
|
if ret['language_version'] == C.DEFAULT:
|
||||||
ret['language_version'] = languages[lang].get_default_version()
|
ret['language_version'] = languages[lang].get_default_version()
|
||||||
|
|
||||||
|
if not ret['stages']:
|
||||||
|
ret['stages'] = root_config['default_stages']
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -715,6 +715,7 @@ def test_local_python_repo(store, local_python_config):
|
||||||
def test_default_language_version(store, local_python_config):
|
def test_default_language_version(store, local_python_config):
|
||||||
config = {
|
config = {
|
||||||
'default_language_version': {'python': 'fake'},
|
'default_language_version': {'python': 'fake'},
|
||||||
|
'default_stages': ['commit'],
|
||||||
'repos': [local_python_config],
|
'repos': [local_python_config],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -728,6 +729,23 @@ def test_default_language_version(store, local_python_config):
|
||||||
assert hook.language_version == 'fake2'
|
assert hook.language_version == 'fake2'
|
||||||
|
|
||||||
|
|
||||||
|
def test_default_stages(store, local_python_config):
|
||||||
|
config = {
|
||||||
|
'default_language_version': {'python': C.DEFAULT},
|
||||||
|
'default_stages': ['commit'],
|
||||||
|
'repos': [local_python_config],
|
||||||
|
}
|
||||||
|
|
||||||
|
# `stages` was not set, should default
|
||||||
|
hook, = all_hooks(config, store)
|
||||||
|
assert hook.stages == ['commit']
|
||||||
|
|
||||||
|
# `stages` is set, should not default
|
||||||
|
config['repos'][0]['hooks'][0]['stages'] = ['push']
|
||||||
|
hook, = all_hooks(config, store)
|
||||||
|
assert hook.stages == ['push']
|
||||||
|
|
||||||
|
|
||||||
def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
|
def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
|
||||||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
|
|
@ -786,13 +804,13 @@ def test_manifest_hooks(tempdir_factory, store):
|
||||||
files='',
|
files='',
|
||||||
id='bash_hook',
|
id='bash_hook',
|
||||||
language='script',
|
language='script',
|
||||||
language_version=C.DEFAULT,
|
language_version='default',
|
||||||
log_file='',
|
log_file='',
|
||||||
minimum_pre_commit_version='0',
|
minimum_pre_commit_version='0',
|
||||||
name='Bash hook',
|
name='Bash hook',
|
||||||
pass_filenames=True,
|
pass_filenames=True,
|
||||||
require_serial=False,
|
require_serial=False,
|
||||||
stages=[],
|
stages=('commit', 'commit-msg', 'manual', 'push'),
|
||||||
types=['file'],
|
types=['file'],
|
||||||
verbose=False,
|
verbose=False,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue