From 79c8b1fceb4ddf6f396f7d46ac1168faee2ffb6e Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 26 Dec 2018 09:05:37 +0000 Subject: [PATCH] Allow hook alias to be used in `SKIP`. Includes test. --- pre_commit/commands/run.py | 9 +++++++++ tests/commands/run_test.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 713603b3..2fb107b7 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -86,6 +86,15 @@ def _run_single_hook(filenames, hook, repo, args, skips, cols): cols=cols, )) return 0 + elif hook['alias'] and hook['alias'] in skips: + output.write(get_hook_message( + _hook_msg_start(hook, args.verbose), + end_msg=SKIPPED, + end_color=color.YELLOW, + use_color=args.color, + cols=cols, + )) + return 0 elif not filenames and not hook['always_run']: output.write(get_hook_message( _hook_msg_start(hook, args.verbose), diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py index 1cec51f2..c3d1ec5d 100644 --- a/tests/commands/run_test.py +++ b/tests/commands/run_test.py @@ -388,6 +388,38 @@ def test_skip_hook(cap_out, store, repo_with_passing_hook): assert msg in printed +def test_skip_aliased_hook(cap_out, store, repo_with_passing_hook): + with cwd(repo_with_passing_hook): + # Add bash hook on there again, aliased + with modify_config() as config: + config['repos'][0]['hooks'].append( + {'id': 'bash_hook', 'alias': 'foo_bash'}, + ) + stage_a_file() + + ret, printed = _do_run( + cap_out, store, repo_with_passing_hook, + run_opts(hook='bash_hook'), + {'SKIP': 'bash_hook'}, + ) + assert ret == 0 + # Both hooks will run since they share the same ID + assert printed.count(b'Bash hook') == 2 + for msg in (b'Bash hook', b'Skipped'): + assert msg in printed + + ret, printed = _do_run( + cap_out, store, repo_with_passing_hook, + run_opts(hook='foo_bash'), + {'SKIP': 'foo_bash'}, + ) + assert ret == 0 + # Only the aliased hook runs + assert printed.count(b'Bash hook') == 1 + for msg in (b'Bash hook', b'Skipped'): + assert msg in printed, printed + + def test_hook_id_not_in_non_verbose_output( cap_out, store, repo_with_passing_hook, ):