diff --git a/pre_commit/clientlib/validate_config.py b/pre_commit/clientlib/validate_config.py index 1da54f91..8991850e 100644 --- a/pre_commit/clientlib/validate_config.py +++ b/pre_commit/clientlib/validate_config.py @@ -32,6 +32,7 @@ CONFIG_JSON_SCHEMA = { 'type': 'object', 'properties': { 'id': {'type': 'string'}, + 'always_run': {'type': 'boolean'}, 'files': {'type': 'string'}, 'exclude': {'type': 'string'}, 'language_version': {'type': 'string'}, diff --git a/pre_commit/clientlib/validate_manifest.py b/pre_commit/clientlib/validate_manifest.py index 094c8e5d..2b7148fd 100644 --- a/pre_commit/clientlib/validate_manifest.py +++ b/pre_commit/clientlib/validate_manifest.py @@ -17,6 +17,7 @@ MANIFEST_JSON_SCHEMA = { 'type': 'object', 'properties': { 'id': {'type': 'string'}, + 'always_run': {'type': 'boolean'}, 'name': {'type': 'string'}, 'description': {'type': 'string', 'default': ''}, 'entry': {'type': 'string'}, diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index e01c7f9f..82e494dd 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -72,13 +72,19 @@ def get_filenames(args, include_expr, exclude_expr): def _run_single_hook(hook, repo, args, write, skips=frozenset()): - filenames = get_filenames(args, hook['files'], hook['exclude']) + filenames = [] + # if the hook is marked as always_run, do not compute the files to run + # in that case, simply run the script once not matter the changes + compute_file_names = 'always_run' not in hook or not hook['always_run'] + if hook['id'] in skips: _print_user_skipped(hook, write, args) return 0 - elif not filenames: - _print_no_files_skipped(hook, write, args) - return 0 + elif compute_file_names: + filenames = get_filenames(args, hook['files'], hook['exclude']) + if not filenames: + _print_no_files_skipped(hook, write, args) + return 0 # Print the hook and the dots first in case the hook takes hella long to # run.