diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py index 9e1e79f2..a446a172 100644 --- a/pre_commit/commands/autoupdate.py +++ b/pre_commit/commands/autoupdate.py @@ -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() diff --git a/testing/fixtures.py b/testing/fixtures.py index 820a72be..a311b20e 100644 --- a/testing/fixtures.py +++ b/testing/fixtures.py @@ -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): diff --git a/tests/commands/autoupdate_test.py b/tests/commands/autoupdate_test.py index 771e67b1..f067a16c 100644 --- a/tests/commands/autoupdate_test.py +++ b/tests/commands/autoupdate_test.py @@ -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