mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Add --allow-missing-config option to install
When no '.pre-commit-config.yaml' file exists while `pre-commit` hooks are enabled, `pre-commit` returns an error and the action is aborted. This is a very common scenario when pre-commit is added later on a project and the user wants to work on a previous branch where the configuration file does not exist. This commits allow the user to optionally install the `pre-commit` hooks with an option to allow a missing configuration and trigger only the legacy pre-commit hooks (if any) when it is missing.
This commit is contained in:
parent
41dcaff3fb
commit
2f4199850d
5 changed files with 84 additions and 2 deletions
|
|
@ -75,6 +75,13 @@ def main(argv=None):
|
|||
'-t', '--hook-type', choices=('pre-commit', 'pre-push'),
|
||||
default='pre-commit',
|
||||
)
|
||||
install_parser.add_argument(
|
||||
'--allow-missing-config', action='store_true', default=False,
|
||||
help=(
|
||||
'Whether to allow a missing `pre-config` configuration file '
|
||||
'or exit with a failure code.'
|
||||
),
|
||||
)
|
||||
|
||||
install_hooks_parser = subparsers.add_parser(
|
||||
'install-hooks',
|
||||
|
|
@ -182,6 +189,7 @@ def main(argv=None):
|
|||
return install(
|
||||
runner, overwrite=args.overwrite, hooks=args.install_hooks,
|
||||
hook_type=args.hook_type,
|
||||
skip_on_missing_conf=args.allow_missing_config
|
||||
)
|
||||
elif args.command == 'install-hooks':
|
||||
return install_hooks(runner)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue