Skip to content

Commit 5a08204

Browse files
author
Laurent Sigal
committed
Allow to simply run a script once - no matter what the changes are
1 parent 577d8a1 commit 5a08204

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

pre_commit/clientlib/validate_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class InvalidConfigError(FatalError):
3232
'type': 'object',
3333
'properties': {
3434
'id': {'type': 'string'},
35+
'always_run': {'type': 'boolean'},
3536
'files': {'type': 'string'},
3637
'exclude': {'type': 'string'},
3738
'language_version': {'type': 'string'},

pre_commit/clientlib/validate_manifest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class InvalidManifestError(ValueError):
1717
'type': 'object',
1818
'properties': {
1919
'id': {'type': 'string'},
20+
'always_run': {'type': 'boolean'},
2021
'name': {'type': 'string'},
2122
'description': {'type': 'string', 'default': ''},
2223
'entry': {'type': 'string'},

pre_commit/commands/run.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,19 @@ def get_filenames(args, include_expr, exclude_expr):
7272

7373

7474
def _run_single_hook(hook, repo, args, write, skips=frozenset()):
75-
filenames = get_filenames(args, hook['files'], hook['exclude'])
75+
filenames = []
76+
# if the hook is marked as always_run, do not compute the files to run
77+
# in that case, simply run the script once not matter the changes
78+
compute_file_names = 'always_run' not in hook or not hook['always_run']
79+
7680
if hook['id'] in skips:
7781
_print_user_skipped(hook, write, args)
7882
return 0
79-
elif not filenames:
80-
_print_no_files_skipped(hook, write, args)
81-
return 0
83+
elif compute_file_names:
84+
filenames = get_filenames(args, hook['files'], hook['exclude'])
85+
if not filenames:
86+
_print_no_files_skipped(hook, write, args)
87+
return 0
8288

8389
# Print the hook and the dots first in case the hook takes hella long to
8490
# run.

0 commit comments

Comments
 (0)