Merge pull request #324 from laurentsigal/allow_always_run

Allow to simply run a script once - no matter what the changes are
This commit is contained in:
Anthony Sottile 2015-12-22 16:05:32 -05:00
commit 7d234e2062
5 changed files with 11 additions and 1 deletions

View file

@ -32,6 +32,7 @@ CONFIG_JSON_SCHEMA = {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
'id': {'type': 'string'}, 'id': {'type': 'string'},
'always_run': {'type': 'boolean'},
'files': {'type': 'string'}, 'files': {'type': 'string'},
'exclude': {'type': 'string'}, 'exclude': {'type': 'string'},
'language_version': {'type': 'string'}, 'language_version': {'type': 'string'},

View file

@ -17,6 +17,7 @@ MANIFEST_JSON_SCHEMA = {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
'id': {'type': 'string'}, 'id': {'type': 'string'},
'always_run': {'type': 'boolean', 'default': False},
'name': {'type': 'string'}, 'name': {'type': 'string'},
'description': {'type': 'string', 'default': ''}, 'description': {'type': 'string', 'default': ''},
'entry': {'type': 'string'}, 'entry': {'type': 'string'},

View file

@ -76,7 +76,7 @@ def _run_single_hook(hook, repo, args, write, skips=frozenset()):
if hook['id'] in skips: if hook['id'] in skips:
_print_user_skipped(hook, write, args) _print_user_skipped(hook, write, args)
return 0 return 0
elif not filenames: elif not filenames and not hook['always_run']:
_print_no_files_skipped(hook, write, args) _print_no_files_skipped(hook, write, args)
return 0 return 0

View file

@ -184,6 +184,12 @@ def test_run(
_test_run(repo_with_passing_hook, options, outputs, expected_ret, stage) _test_run(repo_with_passing_hook, options, outputs, expected_ret, stage)
def test_always_run(repo_with_passing_hook, mock_out_store_directory):
with modify_config() as config:
config[0]['hooks'][0]['always_run'] = True
_test_run(repo_with_passing_hook, {}, (b'Bash hook', b'Passed'), 0, False)
@pytest.mark.parametrize( @pytest.mark.parametrize(
('origin', 'source', 'expect_failure'), ('origin', 'source', 'expect_failure'),
( (

View file

@ -19,6 +19,7 @@ def manifest(store, tempdir_factory):
def test_manifest_contents(manifest): def test_manifest_contents(manifest):
# Should just retrieve the manifest contents # Should just retrieve the manifest contents
assert manifest.manifest_contents == [{ assert manifest.manifest_contents == [{
'always_run': False,
'args': [], 'args': [],
'description': '', 'description': '',
'entry': 'bin/hook.sh', 'entry': 'bin/hook.sh',
@ -35,6 +36,7 @@ def test_manifest_contents(manifest):
def test_hooks(manifest): def test_hooks(manifest):
assert manifest.hooks['bash_hook'] == { assert manifest.hooks['bash_hook'] == {
'always_run': False,
'args': [], 'args': [],
'description': '', 'description': '',
'entry': 'bin/hook.sh', 'entry': 'bin/hook.sh',