Merge pull request #243 from Lucas-C/master

Fixing bug with local hooks that disappeared during autoupdate
This commit is contained in:
Anthony Sottile 2015-06-14 14:34:29 -07:00
commit 72c82f06e1
3 changed files with 27 additions and 3 deletions

View file

@ -69,6 +69,7 @@ def autoupdate(runner):
for repo_config in input_configs: for repo_config in input_configs:
if is_local_hooks(repo_config): if is_local_hooks(repo_config):
output_configs.append(repo_config)
continue continue
sys.stdout.write('Updating {0}...'.format(repo_config['repo'])) sys.stdout.write('Updating {0}...'.format(repo_config['repo']))
sys.stdout.flush() 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): def write_config(directory, config):
if type(config) is not list:
assert type(config) is OrderedDict assert type(config) is OrderedDict
config = [config]
with io.open(os.path.join(directory, C.CONFIG_FILE), 'w') as config_file: 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): def add_config_to_repo(git_path, config):

View file

@ -5,6 +5,7 @@ import shutil
import pytest import pytest
import pre_commit.constants as C 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 _update_repository
from pre_commit.commands.autoupdate import autoupdate from pre_commit.commands.autoupdate import autoupdate
from pre_commit.commands.autoupdate import RepositoryCannotBeUpdatedError from pre_commit.commands.autoupdate import RepositoryCannotBeUpdatedError
@ -146,4 +147,24 @@ def test_autoupdate_local_hooks(tmpdir_factory):
git_path = git_dir(tmpdir_factory) git_path = git_dir(tmpdir_factory)
config = config_with_local_hooks() config = config_with_local_hooks()
path = add_config_to_repo(git_path, config) 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