99import sys
1010
1111from pre_commit .logging_handler import LoggingHandler
12+ from pre_commit .util import resource_filename
1213
1314
1415logger = logging .getLogger ('pre_commit' )
@@ -41,19 +42,10 @@ def make_executable(filename):
4142 )
4243
4344
44- def get_hook_path (runner , hook_type ):
45- if hook_type == 'pre-commit' :
46- hook_path = runner .pre_commit_path
47- legacy_path = runner .pre_commit_legacy_path
48- else :
49- hook_path = runner .pre_push_path
50- legacy_path = runner .pre_push_legacy_path
51- return hook_path , legacy_path
52-
53-
5445def install (runner , overwrite = False , hooks = False , hook_type = 'pre-commit' ):
5546 """Install the pre-commit hooks."""
56- hook_path , legacy_path = get_hook_path (runner , hook_type )
47+ hook_path = runner .get_hook_path (hook_type )
48+ legacy_path = hook_path + '.legacy'
5749
5850 # If we have an existing hook, move it to pre-commit.legacy
5951 if (
@@ -76,12 +68,12 @@ def install(runner, overwrite=False, hooks=False, hook_type='pre-commit'):
7668
7769 with io .open (hook_path , 'w' ) as pre_commit_file_obj :
7870 if hook_type == 'pre-push' :
79- with io .open (runner . pre_push_template ) as fp :
71+ with io .open (resource_filename ( 'pre-push-tmpl' ) ) as fp :
8072 pre_push_contents = fp .read ()
8173 else :
8274 pre_push_contents = ''
8375
84- contents = io .open (runner . pre_template ).read ().format (
76+ contents = io .open (resource_filename ( 'hook-tmpl' ) ).read ().format (
8577 sys_executable = sys .executable ,
8678 hook_type = hook_type ,
8779 pre_push = pre_push_contents ,
@@ -104,7 +96,8 @@ def install(runner, overwrite=False, hooks=False, hook_type='pre-commit'):
10496
10597def uninstall (runner , hook_type = 'pre-commit' ):
10698 """Uninstall the pre-commit hooks."""
107- hook_path , legacy_path = get_hook_path (runner , hook_type )
99+ hook_path = runner .get_hook_path (hook_type )
100+ legacy_path = hook_path + '.legacy'
108101 # If our file doesn't exist or it isn't ours, gtfo.
109102 if (
110103 not os .path .exists (hook_path ) or (
0 commit comments