mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add an install-hooks command (similar to install --install-hooks). Resolves #456
This commit is contained in:
parent
8837cfa7ff
commit
f238495d6b
4 changed files with 51 additions and 10 deletions
|
|
@ -82,12 +82,16 @@ def install(runner, overwrite=False, hooks=False, hook_type='pre-commit'):
|
|||
|
||||
# If they requested we install all of the hooks, do so.
|
||||
if hooks:
|
||||
for repository in runner.repositories:
|
||||
repository.require_installed()
|
||||
install_hooks(runner)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def install_hooks(runner):
|
||||
for repository in runner.repositories:
|
||||
repository.require_installed()
|
||||
|
||||
|
||||
def uninstall(runner, hook_type='pre-commit'):
|
||||
"""Uninstall the pre-commit hooks."""
|
||||
hook_path = runner.get_hook_path(hook_type)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from pre_commit import git
|
|||
from pre_commit.commands.autoupdate import autoupdate
|
||||
from pre_commit.commands.clean import clean
|
||||
from pre_commit.commands.install_uninstall import install
|
||||
from pre_commit.commands.install_uninstall import install_hooks
|
||||
from pre_commit.commands.install_uninstall import uninstall
|
||||
from pre_commit.commands.run import run
|
||||
from pre_commit.error_handler import error_handler
|
||||
|
|
@ -78,6 +79,17 @@ def main(argv=None):
|
|||
default='pre-commit',
|
||||
)
|
||||
|
||||
install_hooks_parser = subparsers.add_parser(
|
||||
'install-hooks',
|
||||
help=(
|
||||
'Install hook environemnts for all environemnts in the config '
|
||||
'file. You may find `pre-commit install --install-hooks` more '
|
||||
'useful.'
|
||||
),
|
||||
)
|
||||
_add_color_option(install_hooks_parser)
|
||||
_add_config_option(install_hooks_parser)
|
||||
|
||||
uninstall_parser = subparsers.add_parser(
|
||||
'uninstall', help='Uninstall the pre-commit script.',
|
||||
)
|
||||
|
|
@ -171,6 +183,8 @@ def main(argv=None):
|
|||
runner, overwrite=args.overwrite, hooks=args.install_hooks,
|
||||
hook_type=args.hook_type,
|
||||
)
|
||||
elif args.command == 'install-hooks':
|
||||
return install_hooks(runner)
|
||||
elif args.command == 'uninstall':
|
||||
return uninstall(runner, hook_type=args.hook_type)
|
||||
elif args.command == 'clean':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue