mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add a helper to modify config files under test
This commit is contained in:
parent
336939ef99
commit
be4d0a2742
2 changed files with 54 additions and 60 deletions
|
|
@ -48,6 +48,20 @@ def modify_manifest(path):
|
|||
cmd_output('git', 'commit', '-am', 'update hooks.yaml', cwd=path)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def modify_config(path='.', commit=True):
|
||||
"""Modify the config yielded by this context to write to
|
||||
.pre-commit-config.yaml
|
||||
"""
|
||||
config_path = os.path.join(path, C.CONFIG_FILE)
|
||||
config = ordered_load(io.open(config_path).read())
|
||||
yield config
|
||||
with io.open(config_path, 'w', encoding='UTF-8') as config_file:
|
||||
config_file.write(ordered_dump(config, **C.YAML_DUMP_KWARGS))
|
||||
if commit:
|
||||
cmd_output('git', 'commit', '-am', 'update config', cwd=path)
|
||||
|
||||
|
||||
def config_with_local_hooks():
|
||||
return OrderedDict((
|
||||
('repo', 'local'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue