Fixing bug with local hooks that disappeared during autoupdate

This commit is contained in:
Lucas Cimon
2015-06-14 22:30:23 +02:00
parent 2a642b0619
commit 3c02a24655
3 changed files with 27 additions and 3 deletions

View File

@@ -69,6 +69,7 @@ def autoupdate(runner):
for repo_config in input_configs:
if is_local_hooks(repo_config):
output_configs.append(repo_config)
continue
sys.stdout.write('Updating {0}...'.format(repo_config['repo']))
sys.stdout.flush()

View File

@@ -68,9 +68,11 @@ def make_config_from_repo(repo_path, sha=None, hooks=None, check=True):
def write_config(directory, config):
assert type(config) is OrderedDict
if type(config) is not list:
assert type(config) is OrderedDict
config = [config]
with io.open(os.path.join(directory, C.CONFIG_FILE), 'w') as config_file:
config_file.write(ordered_dump([config], **C.YAML_DUMP_KWARGS))
config_file.write(ordered_dump(config, **C.YAML_DUMP_KWARGS))
def add_config_to_repo(git_path, config):

View File

@@ -5,6 +5,7 @@ import shutil
import pytest
import pre_commit.constants as C
from pre_commit.clientlib.validate_config import load_config
from pre_commit.commands.autoupdate import _update_repository
from pre_commit.commands.autoupdate import autoupdate
from pre_commit.commands.autoupdate import RepositoryCannotBeUpdatedError
@@ -146,4 +147,24 @@ def test_autoupdate_local_hooks(tmpdir_factory):
git_path = git_dir(tmpdir_factory)
config = config_with_local_hooks()
path = add_config_to_repo(git_path, config)
assert autoupdate(Runner(path)) == 0
runner = Runner(path)
assert autoupdate(runner) == 0
new_config_writen = load_config(runner.config_file_path)
assert len(new_config_writen) == 1
assert new_config_writen[0] == config
def test_autoupdate_local_hooks_with_out_of_date_repo(
out_of_date_repo, in_tmpdir, mock_out_store_directory
):
stale_config = make_config_from_repo(
out_of_date_repo.path, sha=out_of_date_repo.original_sha, check=False,
)
local_config = config_with_local_hooks()
config = [local_config, stale_config]
write_config('.', config)
runner = Runner('.')
assert autoupdate(runner) == 0
new_config_writen = load_config(runner.config_file_path)
assert len(new_config_writen) == 2
assert new_config_writen[0] == local_config