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

Skip to content

Commit 8ffd1f6

Browse files
committed
Address review comments
1 parent 79c8b1f commit 8ffd1f6

2 files changed

Lines changed: 19 additions & 32 deletions

File tree

pre_commit/commands/run.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,7 @@ def _run_single_hook(filenames, hook, repo, args, skips, cols):
7777
'replacement.'.format(hook['id'], repo.repo_config['repo']),
7878
)
7979

80-
if hook['id'] in skips:
81-
output.write(get_hook_message(
82-
_hook_msg_start(hook, args.verbose),
83-
end_msg=SKIPPED,
84-
end_color=color.YELLOW,
85-
use_color=args.color,
86-
cols=cols,
87-
))
88-
return 0
89-
elif hook['alias'] and hook['alias'] in skips:
80+
if hook['id'] in skips or hook['alias'] in skips:
9081
output.write(get_hook_message(
9182
_hook_msg_start(hook, args.verbose),
9283
end_msg=SKIPPED,

tests/commands/run_test.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ def repo_with_failing_hook(tempdir_factory):
4242
yield git_path
4343

4444

45+
@pytest.fixture
46+
def aliased_repo(tempdir_factory):
47+
git_path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
48+
with cwd(git_path):
49+
with modify_config() as config:
50+
config['repos'][0]['hooks'].append(
51+
{'id': 'bash_hook', 'alias': 'foo_bash'},
52+
)
53+
stage_a_file()
54+
yield git_path
55+
56+
4557
def stage_a_file(filename='foo.py'):
4658
open(filename, 'a').close()
4759
cmd_output('git', 'add', filename)
@@ -388,17 +400,9 @@ def test_skip_hook(cap_out, store, repo_with_passing_hook):
388400
assert msg in printed
389401

390402

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-
403+
def test_skip_aliased_hook(cap_out, store, aliased_repo):
400404
ret, printed = _do_run(
401-
cap_out, store, repo_with_passing_hook,
405+
cap_out, store, aliased_repo,
402406
run_opts(hook='bash_hook'),
403407
{'SKIP': 'bash_hook'},
404408
)
@@ -409,7 +413,7 @@ def test_skip_aliased_hook(cap_out, store, repo_with_passing_hook):
409413
assert msg in printed
410414

411415
ret, printed = _do_run(
412-
cap_out, store, repo_with_passing_hook,
416+
cap_out, store, aliased_repo,
413417
run_opts(hook='foo_bash'),
414418
{'SKIP': 'foo_bash'},
415419
)
@@ -448,25 +452,17 @@ def test_multiple_hooks_same_id(cap_out, store, repo_with_passing_hook):
448452
assert output.count(b'Bash hook') == 2
449453

450454

451-
def test_aliased_hook_run(cap_out, store, repo_with_passing_hook):
452-
with cwd(repo_with_passing_hook):
453-
# Add bash hook on there again, aliased
454-
with modify_config() as config:
455-
config['repos'][0]['hooks'].append(
456-
{'id': 'bash_hook', 'alias': 'foo_bash'},
457-
)
458-
stage_a_file()
459-
455+
def test_aliased_hook_run(cap_out, store, aliased_repo):
460456
ret, output = _do_run(
461-
cap_out, store, repo_with_passing_hook,
457+
cap_out, store, aliased_repo,
462458
run_opts(verbose=True, hook='bash_hook'),
463459
)
464460
assert ret == 0
465461
# Both hooks will run since they share the same ID
466462
assert output.count(b'Bash hook') == 2
467463

468464
ret, output = _do_run(
469-
cap_out, store, repo_with_passing_hook,
465+
cap_out, store, aliased_repo,
470466
run_opts(verbose=True, hook='foo_bash'),
471467
)
472468
assert ret == 0

0 commit comments

Comments
 (0)