@@ -60,6 +60,7 @@ def _get_opts(
6060 allow_unstaged_config = False ,
6161 hook_stage = 'commit' ,
6262 show_diff_on_failure = False ,
63+ commit_msg_filename = '' ,
6364):
6465 # These are mutually exclusive
6566 assert not (all_files and files )
@@ -75,6 +76,7 @@ def _get_opts(
7576 allow_unstaged_config = allow_unstaged_config ,
7677 hook_stage = hook_stage ,
7778 show_diff_on_failure = show_diff_on_failure ,
79+ commit_msg_filename = commit_msg_filename ,
7880 )
7981
8082
@@ -572,78 +574,69 @@ def test_lots_of_files(mock_out_store_directory, tempdir_factory):
572574 )
573575
574576
575- @pytest .mark .parametrize (
576- (
577- 'hook_stage' , 'stage_for_first_hook' , 'stage_for_second_hook' ,
578- 'expected_output' ,
579- ),
580- (
581- ('push' , ['commit' ], ['commit' ], [b'' , b'' ]),
582- (
583- 'push' , ['commit' , 'push' ], ['commit' , 'push' ],
584- [b'hook 1' , b'hook 2' ],
585- ),
586- ('push' , [], [], [b'hook 1' , b'hook 2' ]),
587- ('push' , [], ['commit' ], [b'hook 1' , b'' ]),
588- ('push' , ['push' ], ['commit' ], [b'hook 1' , b'' ]),
589- ('push' , ['commit' ], ['push' ], [b'' , b'hook 2' ]),
590- (
591- 'commit' , ['commit' , 'push' ], ['commit' , 'push' ],
592- [b'hook 1' , b'hook 2' ],
593- ),
594- ('commit' , ['commit' ], ['commit' ], [b'hook 1' , b'hook 2' ]),
595- ('commit' , [], [], [b'hook 1' , b'hook 2' ]),
596- ('commit' , [], ['commit' ], [b'hook 1' , b'hook 2' ]),
597- ('commit' , ['push' ], ['commit' ], [b'' , b'hook 2' ]),
598- ('commit' , ['commit' ], ['push' ], [b'hook 1' , b'' ]),
599- ),
600- )
601- def test_local_hook_for_stages (
602- cap_out ,
603- repo_with_passing_hook , mock_out_store_directory ,
604- stage_for_first_hook ,
605- stage_for_second_hook ,
606- hook_stage ,
607- expected_output ,
608- ):
577+ def test_push_hook (cap_out , repo_with_passing_hook , mock_out_store_directory ):
609578 config = OrderedDict ((
610579 ('repo' , 'local' ),
611580 (
612581 'hooks' , (
613582 OrderedDict ((
614583 ('id' , 'flake8' ),
615584 ('name' , 'hook 1' ),
616- ('entry' , 'python -m flake8.__main__' ),
585+ ('entry' , "'{}' -m flake8" . format ( sys . executable ) ),
617586 ('language' , 'system' ),
618- ('files' , r'\.py$' ),
619- ('stages' , stage_for_first_hook ),
620- )), OrderedDict ((
587+ ('types' , ['python' ]),
588+ ('stages' , ['commit' ]),
589+ )),
590+ OrderedDict ((
621591 ('id' , 'do_not_commit' ),
622592 ('name' , 'hook 2' ),
623593 ('entry' , 'DO NOT COMMIT' ),
624594 ('language' , 'pcre' ),
625- ('files ' , '^(.*)$' ),
626- ('stages' , stage_for_second_hook ),
595+ ('types ' , [ 'text' ] ),
596+ ('stages' , [ 'push' ] ),
627597 )),
628598 ),
629599 ),
630600 ))
631601 add_config_to_repo (repo_with_passing_hook , config )
632602
633- with io .open ('dummy.py' , 'w' ) as staged_file :
634- staged_file .write ('"""TODO: something"""\n ' )
603+ open ('dummy.py' , 'a' ).close ()
635604 cmd_output ('git' , 'add' , 'dummy.py' )
636605
637606 _test_run (
638607 cap_out ,
639608 repo_with_passing_hook ,
640- {'hook_stage' : hook_stage },
641- expected_outputs = expected_output ,
609+ {'hook_stage' : 'commit' },
610+ expected_outputs = [b'hook 1' ],
611+ expected_ret = 0 ,
612+ stage = False ,
613+ )
614+
615+ _test_run (
616+ cap_out ,
617+ repo_with_passing_hook ,
618+ {'hook_stage' : 'push' },
619+ expected_outputs = [b'hook 2' ],
642620 expected_ret = 0 ,
643621 stage = False ,
644622 )
645623
646624
625+ def test_commit_msg_hook (cap_out , commit_msg_repo , mock_out_store_directory ):
626+ filename = '.git/COMMIT_EDITMSG'
627+ with io .open (filename , 'w' ) as f :
628+ f .write ('This is the commit message' )
629+
630+ _test_run (
631+ cap_out ,
632+ commit_msg_repo ,
633+ {'hook_stage' : 'commit-msg' , 'commit_msg_filename' : filename },
634+ expected_outputs = [b'Must have "Signed off by:"' , b'Failed' ],
635+ expected_ret = 1 ,
636+ stage = False ,
637+ )
638+
639+
647640def test_local_hook_passes (
648641 cap_out , repo_with_passing_hook , mock_out_store_directory ,
649642):
@@ -654,7 +647,7 @@ def test_local_hook_passes(
654647 OrderedDict ((
655648 ('id' , 'flake8' ),
656649 ('name' , 'flake8' ),
657- ('entry' , 'python -m flake8.__main__' ),
650+ ('entry' , "'{}' -m flake8" . format ( sys . executable ) ),
658651 ('language' , 'system' ),
659652 ('files' , r'\.py$' ),
660653 )), OrderedDict ((
0 commit comments