@@ -31,15 +31,15 @@ def test_is_not_our_pre_commit():
3131
3232
3333def test_is_our_pre_commit ():
34- assert is_our_pre_commit (resource_filename ('pre-commit- hook' ))
34+ assert is_our_pre_commit (resource_filename ('hook-tmpl ' ))
3535
3636
3737def test_is_not_previous_pre_commit ():
3838 assert is_previous_pre_commit ('setup.py' ) is False
3939
4040
4141def test_is_also_not_previous_pre_commit ():
42- assert not is_previous_pre_commit (resource_filename ('pre-commit- hook' ))
42+ assert not is_previous_pre_commit (resource_filename ('hook-tmpl ' ))
4343
4444
4545def test_is_previous_pre_commit (in_tmpdir ):
@@ -56,14 +56,29 @@ def test_install_pre_commit(tmpdir_factory):
5656 assert ret == 0
5757 assert os .path .exists (runner .pre_commit_path )
5858 pre_commit_contents = io .open (runner .pre_commit_path ).read ()
59- pre_commit_script = resource_filename ('pre-commit- hook' )
59+ pre_commit_script = resource_filename ('hook-tmpl ' )
6060 expected_contents = io .open (pre_commit_script ).read ().format (
6161 sys_executable = sys .executable ,
62+ hook_type = 'pre-commit' ,
63+ pre_push = ''
6264 )
6365 assert pre_commit_contents == expected_contents
6466 stat_result = os .stat (runner .pre_commit_path )
6567 assert stat_result .st_mode & (stat .S_IXUSR | stat .S_IXGRP | stat .S_IXOTH )
6668
69+ ret = install (runner , hook_type = 'pre-push' )
70+ assert ret == 0
71+ assert os .path .exists (runner .pre_push_path )
72+ pre_push_contents = io .open (runner .pre_push_path ).read ()
73+ pre_push_tmpl = resource_filename ('pre-push-tmpl' )
74+ pre_push_template_contents = io .open (pre_push_tmpl ).read ()
75+ expected_contents = io .open (pre_commit_script ).read ().format (
76+ sys_executable = sys .executable ,
77+ hook_type = 'pre-push' ,
78+ pre_push = pre_push_template_contents ,
79+ )
80+ assert pre_push_contents == expected_contents
81+
6782
6883def test_uninstall_does_not_blow_up_when_not_there (tmpdir_factory ):
6984 path = git_dir (tmpdir_factory )
@@ -322,7 +337,7 @@ def test_replace_old_commit_script(tmpdir_factory):
322337
323338 # Install a script that looks like our old script
324339 pre_commit_contents = io .open (
325- resource_filename ('pre-commit- hook' ),
340+ resource_filename ('hook-tmpl ' ),
326341 ).read ()
327342 new_contents = pre_commit_contents .replace (
328343 IDENTIFYING_HASH , PREVIOUS_IDENTIFYING_HASHES [- 1 ],
@@ -391,3 +406,46 @@ def test_installed_from_venv(tmpdir_factory):
391406 )
392407 assert ret == 0
393408 assert NORMAL_PRE_COMMIT_RUN .match (output )
409+
410+
411+ def _get_push_output (tmpdir_factory ):
412+ # Don't want to write to home directory
413+ home = tmpdir_factory .get ()
414+ env = dict (os .environ , ** {'PRE_COMMIT_HOME' : home })
415+ return cmd_output (
416+ 'git' , 'push' , 'origin' , 'HEAD:new_branch' ,
417+ # git commit puts pre-commit to stderr
418+ stderr = subprocess .STDOUT ,
419+ env = env ,
420+ retcode = None ,
421+ )[:2 ]
422+
423+
424+ def test_pre_push_integration_failing (tmpdir_factory ):
425+ upstream = make_consuming_repo (tmpdir_factory , 'failing_hook_repo' )
426+ path = tmpdir_factory .get ()
427+ cmd_output ('git' , 'clone' , upstream , path )
428+ with cwd (path ):
429+ install (Runner (path ), hook_type = 'pre-push' )
430+ # commit succeeds because pre-commit is only installed for pre-push
431+ assert _get_commit_output (tmpdir_factory )[0 ] == 0
432+
433+ retc , output = _get_push_output (tmpdir_factory )
434+ assert retc == 1
435+ assert 'Failing hook' in output
436+ assert 'Failed' in output
437+ assert 'hookid: failing_hook' in output
438+
439+
440+ def test_pre_push_integration_accepted (tmpdir_factory ):
441+ upstream = make_consuming_repo (tmpdir_factory , 'script_hooks_repo' )
442+ path = tmpdir_factory .get ()
443+ cmd_output ('git' , 'clone' , upstream , path )
444+ with cwd (path ):
445+ install (Runner (path ), hook_type = 'pre-push' )
446+ assert _get_commit_output (tmpdir_factory )[0 ] == 0
447+
448+ retc , output = _get_push_output (tmpdir_factory )
449+ assert retc == 0
450+ assert 'Bash hook' in output
451+ assert 'Passed' in output
0 commit comments