mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 13:00:10 -06:00
Merge pull request #135 from pre-commit/install_hooks
Support --install-hooks as an option for pre-commit install
This commit is contained in:
@@ -35,7 +35,7 @@ def make_executable(filename):
|
||||
)
|
||||
|
||||
|
||||
def install(runner, overwrite=False):
|
||||
def install(runner, overwrite=False, hooks=False):
|
||||
"""Install the pre-commit hooks."""
|
||||
pre_commit_file = resource_filename('pre-commit-hook')
|
||||
|
||||
@@ -63,6 +63,12 @@ def install(runner, overwrite=False):
|
||||
make_executable(runner.pre_commit_path)
|
||||
|
||||
print('pre-commit installed at {0}'.format(runner.pre_commit_path))
|
||||
|
||||
# If they requested we install all of the hooks, do so.
|
||||
if hooks:
|
||||
for repository in runner.repositories:
|
||||
repository.require_installed()
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,13 @@ def main(argv):
|
||||
'-f', '--overwrite', action='store_true',
|
||||
help='Overwrite existing hooks / remove migration mode.',
|
||||
)
|
||||
install_parser.add_argument(
|
||||
'--install-hooks', action='store_true',
|
||||
help=(
|
||||
'Whether to install hook environments for all environments '
|
||||
'in the config file.'
|
||||
),
|
||||
)
|
||||
|
||||
subparsers.add_parser('uninstall', help='Uninstall the pre-commit script.')
|
||||
|
||||
@@ -79,7 +86,9 @@ def main(argv):
|
||||
runner = Runner.create()
|
||||
|
||||
if args.command == 'install':
|
||||
return install(runner, overwrite=args.overwrite)
|
||||
return install(
|
||||
runner, overwrite=args.overwrite, hooks=args.install_hooks,
|
||||
)
|
||||
elif args.command == 'uninstall':
|
||||
return uninstall(runner)
|
||||
elif args.command == 'clean':
|
||||
|
||||
Reference in New Issue
Block a user