66import os .path
77import sys
88
9+ from pre_commit import git
910from pre_commit import output
1011from pre_commit .repository import repositories
1112from pre_commit .util import cmd_output
2930TEMPLATE_END = '# end templated\n '
3031
3132
33+ def _hook_paths (git_root , hook_type ):
34+ pth = os .path .join (git .get_git_dir (git_root ), 'hooks' , hook_type )
35+ return pth , '{}.legacy' .format (pth )
36+
37+
3238def is_our_script (filename ):
3339 if not os .path .exists (filename ):
3440 return False
@@ -48,8 +54,7 @@ def install(
4854 )
4955 return 1
5056
51- hook_path = runner .get_hook_path (hook_type )
52- legacy_path = hook_path + '.legacy'
57+ hook_path , legacy_path = _hook_paths (runner .git_root , hook_type )
5358
5459 mkdirp (os .path .dirname (hook_path ))
5560
@@ -102,8 +107,8 @@ def install_hooks(runner, store):
102107
103108def uninstall (runner , hook_type = 'pre-commit' ):
104109 """Uninstall the pre-commit hooks."""
105- hook_path = runner .get_hook_path ( hook_type )
106- legacy_path = hook_path + '.legacy'
110+ hook_path , legacy_path = _hook_paths ( runner .git_root , hook_type )
111+
107112 # If our file doesn't exist or it isn't ours, gtfo.
108113 if not os .path .exists (hook_path ) or not is_our_script (hook_path ):
109114 return 0
0 commit comments