mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-17 14:30:05 -06: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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user