mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #787 from pre-commit/hook_paths
hook paths are only computed in install_uninstall
This commit is contained in:
commit
a4b5a9f7fb
3 changed files with 10 additions and 8 deletions
|
|
@ -6,6 +6,7 @@ import logging
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from pre_commit import git
|
||||||
from pre_commit import output
|
from pre_commit import output
|
||||||
from pre_commit.repository import repositories
|
from pre_commit.repository import repositories
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
|
|
@ -29,6 +30,11 @@ TEMPLATE_START = '# start templated\n'
|
||||||
TEMPLATE_END = '# end templated\n'
|
TEMPLATE_END = '# end templated\n'
|
||||||
|
|
||||||
|
|
||||||
|
def _hook_paths(git_root, hook_type):
|
||||||
|
pth = os.path.join(git.get_git_dir(git_root), 'hooks', hook_type)
|
||||||
|
return pth, '{}.legacy'.format(pth)
|
||||||
|
|
||||||
|
|
||||||
def is_our_script(filename):
|
def is_our_script(filename):
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
return False
|
return False
|
||||||
|
|
@ -48,8 +54,7 @@ def install(
|
||||||
)
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
hook_path = runner.get_hook_path(hook_type)
|
hook_path, legacy_path = _hook_paths(runner.git_root, hook_type)
|
||||||
legacy_path = hook_path + '.legacy'
|
|
||||||
|
|
||||||
mkdirp(os.path.dirname(hook_path))
|
mkdirp(os.path.dirname(hook_path))
|
||||||
|
|
||||||
|
|
@ -102,8 +107,8 @@ def install_hooks(runner, store):
|
||||||
|
|
||||||
def uninstall(runner, hook_type='pre-commit'):
|
def uninstall(runner, hook_type='pre-commit'):
|
||||||
"""Uninstall the pre-commit hooks."""
|
"""Uninstall the pre-commit hooks."""
|
||||||
hook_path = runner.get_hook_path(hook_type)
|
hook_path, legacy_path = _hook_paths(runner.git_root, hook_type)
|
||||||
legacy_path = hook_path + '.legacy'
|
|
||||||
# If our file doesn't exist or it isn't ours, gtfo.
|
# If our file doesn't exist or it isn't ours, gtfo.
|
||||||
if not os.path.exists(hook_path) or not is_our_script(hook_path):
|
if not os.path.exists(hook_path) or not is_our_script(hook_path):
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,3 @@ class Runner(object):
|
||||||
@cached_property
|
@cached_property
|
||||||
def config(self):
|
def config(self):
|
||||||
return load_config(self.config_file_path)
|
return load_config(self.config_file_path)
|
||||||
|
|
||||||
def get_hook_path(self, hook_type):
|
|
||||||
return os.path.join(git.get_git_dir(self.git_root), 'hooks', hook_type)
|
|
||||||
|
|
|
||||||
|
|
@ -640,7 +640,7 @@ def test_commit_msg_integration_passing(
|
||||||
def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store):
|
def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store):
|
||||||
runner = Runner(commit_msg_repo, C.CONFIG_FILE)
|
runner = Runner(commit_msg_repo, C.CONFIG_FILE)
|
||||||
|
|
||||||
hook_path = runner.get_hook_path('commit-msg')
|
hook_path = os.path.join(commit_msg_repo, '.git/hooks/commit-msg')
|
||||||
mkdirp(os.path.dirname(hook_path))
|
mkdirp(os.path.dirname(hook_path))
|
||||||
with io.open(hook_path, 'w') as hook_file:
|
with io.open(hook_path, 'w') as hook_file:
|
||||||
hook_file.write(
|
hook_file.write(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue