Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79c8b1f

Browse files
committed
Allow hook alias to be used in SKIP. Includes test.
1 parent 5840f88 commit 79c8b1f

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

pre_commit/commands/run.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ def _run_single_hook(filenames, hook, repo, args, skips, cols):
8686
cols=cols,
8787
))
8888
return 0
89+
elif hook['alias'] and hook['alias'] in skips:
90+
output.write(get_hook_message(
91+
_hook_msg_start(hook, args.verbose),
92+
end_msg=SKIPPED,
93+
end_color=color.YELLOW,
94+
use_color=args.color,
95+
cols=cols,
96+
))
97+
return 0
8998
elif not filenames and not hook['always_run']:
9099
output.write(get_hook_message(
91100
_hook_msg_start(hook, args.verbose),

tests/commands/run_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,38 @@ def test_skip_hook(cap_out, store, repo_with_passing_hook):
388388
assert msg in printed
389389

390390

391+
def test_skip_aliased_hook(cap_out, store, repo_with_passing_hook):
392+
with cwd(repo_with_passing_hook):
393+
# Add bash hook on there again, aliased
394+
with modify_config() as config:
395+
config['repos'][0]['hooks'].append(
396+
{'id': 'bash_hook', 'alias': 'foo_bash'},
397+
)
398+
stage_a_file()
399+
400+
ret, printed = _do_run(
401+
cap_out, store, repo_with_passing_hook,
402+
run_opts(hook='bash_hook'),
403+
{'SKIP': 'bash_hook'},
404+
)
405+
assert ret == 0
406+
# Both hooks will run since they share the same ID
407+
assert printed.count(b'Bash hook') == 2
408+
for msg in (b'Bash hook', b'Skipped'):
409+
assert msg in printed
410+
411+
ret, printed = _do_run(
412+
cap_out, store, repo_with_passing_hook,
413+
run_opts(hook='foo_bash'),
414+
{'SKIP': 'foo_bash'},
415+
)
416+
assert ret == 0
417+
# Only the aliased hook runs
418+
assert printed.count(b'Bash hook') == 1
419+
for msg in (b'Bash hook', b'Skipped'):
420+
assert msg in printed, printed
421+
422+
391423
def test_hook_id_not_in_non_verbose_output(
392424
cap_out, store, repo_with_passing_hook,
393425
):

0 commit comments

Comments
 (0)