Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c02a24

Browse files
committed
Fixing bug with local hooks that disappeared during autoupdate
1 parent 2a642b0 commit 3c02a24

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

pre_commit/commands/autoupdate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def autoupdate(runner):
6969

7070
for repo_config in input_configs:
7171
if is_local_hooks(repo_config):
72+
output_configs.append(repo_config)
7273
continue
7374
sys.stdout.write('Updating {0}...'.format(repo_config['repo']))
7475
sys.stdout.flush()

testing/fixtures.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ def make_config_from_repo(repo_path, sha=None, hooks=None, check=True):
6868

6969

7070
def write_config(directory, config):
71-
assert type(config) is OrderedDict
71+
if type(config) is not list:
72+
assert type(config) is OrderedDict
73+
config = [config]
7274
with io.open(os.path.join(directory, C.CONFIG_FILE), 'w') as config_file:
73-
config_file.write(ordered_dump([config], **C.YAML_DUMP_KWARGS))
75+
config_file.write(ordered_dump(config, **C.YAML_DUMP_KWARGS))
7476

7577

7678
def add_config_to_repo(git_path, config):

tests/commands/autoupdate_test.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
import pre_commit.constants as C
8+
from pre_commit.clientlib.validate_config import load_config
89
from pre_commit.commands.autoupdate import _update_repository
910
from pre_commit.commands.autoupdate import autoupdate
1011
from pre_commit.commands.autoupdate import RepositoryCannotBeUpdatedError
@@ -146,4 +147,24 @@ def test_autoupdate_local_hooks(tmpdir_factory):
146147
git_path = git_dir(tmpdir_factory)
147148
config = config_with_local_hooks()
148149
path = add_config_to_repo(git_path, config)
149-
assert autoupdate(Runner(path)) == 0
150+
runner = Runner(path)
151+
assert autoupdate(runner) == 0
152+
new_config_writen = load_config(runner.config_file_path)
153+
assert len(new_config_writen) == 1
154+
assert new_config_writen[0] == config
155+
156+
157+
def test_autoupdate_local_hooks_with_out_of_date_repo(
158+
out_of_date_repo, in_tmpdir, mock_out_store_directory
159+
):
160+
stale_config = make_config_from_repo(
161+
out_of_date_repo.path, sha=out_of_date_repo.original_sha, check=False,
162+
)
163+
local_config = config_with_local_hooks()
164+
config = [local_config, stale_config]
165+
write_config('.', config)
166+
runner = Runner('.')
167+
assert autoupdate(runner) == 0
168+
new_config_writen = load_config(runner.config_file_path)
169+
assert len(new_config_writen) == 2
170+
assert new_config_writen[0] == local_config

0 commit comments

Comments
 (0)