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:
Filippos Giannakos
2017-02-21 12:40:33 +02:00
parent 41dcaff3fb
commit 2f4199850d
5 changed files with 84 additions and 2 deletions

View File

@@ -123,6 +123,14 @@ def add_config_to_repo(git_path, config, config_file=C.CONFIG_FILE):
return git_path
def remove_config_from_repo(git_path, config_file=C.CONFIG_FILE):
os.unlink(os.path.join(git_path, config_file))
with cwd(git_path):
cmd_output('git', 'add', config_file)
cmd_output('git', 'commit', '-m', 'Remove hooks config')
return git_path
def make_consuming_repo(tempdir_factory, repo_source):
path = make_repo(tempdir_factory, repo_source)
config = make_config_from_repo(path)