@@ -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+
4557def stage_a_file (filename = 'foo.py' ):
4658 open (filename , 'a' ).close ()
4759 cmd_output ('git' , 'add' , filename )
@@ -388,6 +400,18 @@ def test_skip_hook(cap_out, store, repo_with_passing_hook):
388400 assert msg in printed
389401
390402
403+ def test_skip_aliased_hook (cap_out , store , aliased_repo ):
404+ ret , printed = _do_run (
405+ cap_out , store , aliased_repo ,
406+ run_opts (hook = 'foo_bash' ),
407+ {'SKIP' : 'foo_bash' },
408+ )
409+ assert ret == 0
410+ # Only the aliased hook runs and is skipped
411+ for msg in (b'Bash hook' , b'Skipped' ):
412+ assert printed .count (msg ) == 1
413+
414+
391415def test_hook_id_not_in_non_verbose_output (
392416 cap_out , store , repo_with_passing_hook ,
393417):
@@ -416,6 +440,24 @@ def test_multiple_hooks_same_id(cap_out, store, repo_with_passing_hook):
416440 assert output .count (b'Bash hook' ) == 2
417441
418442
443+ def test_aliased_hook_run (cap_out , store , aliased_repo ):
444+ ret , output = _do_run (
445+ cap_out , store , aliased_repo ,
446+ run_opts (verbose = True , hook = 'bash_hook' ),
447+ )
448+ assert ret == 0
449+ # Both hooks will run since they share the same ID
450+ assert output .count (b'Bash hook' ) == 2
451+
452+ ret , output = _do_run (
453+ cap_out , store , aliased_repo ,
454+ run_opts (verbose = True , hook = 'foo_bash' ),
455+ )
456+ assert ret == 0
457+ # Only the aliased hook runs
458+ assert output .count (b'Bash hook' ) == 1
459+
460+
419461def test_non_ascii_hook_id (repo_with_passing_hook , tempdir_factory ):
420462 with cwd (repo_with_passing_hook ):
421463 _ , stdout , _ = cmd_output_mocked_pre_commit_home (
0 commit comments