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

Skip to content

Commit dc84f21

Browse files
authored
Merge pull request #857 from runz0rd/master
Reraises InvalidManifestError as RepositoryCannotBeUpdatedError
2 parents 76e0f11 + aaa3976 commit dc84f21

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

pre_commit/commands/autoupdate.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import re
55
from collections import OrderedDict
66

7+
import six
78
from aspy.yaml import ordered_dump
89
from aspy.yaml import ordered_load
910
from cfgv import remove_defaults
1011

1112
import pre_commit.constants as C
1213
from pre_commit import output
1314
from pre_commit.clientlib import CONFIG_SCHEMA
15+
from pre_commit.clientlib import InvalidManifestError
1416
from pre_commit.clientlib import is_local_repo
1517
from pre_commit.clientlib import is_meta_repo
1618
from pre_commit.clientlib import load_config
@@ -53,11 +55,15 @@ def _update_repo(repo_config, store, tags_only):
5355
# Construct a new config with the head rev
5456
new_config = OrderedDict(repo_config)
5557
new_config['rev'] = rev
56-
new_repo = Repository.create(new_config, store)
58+
59+
try:
60+
new_hooks = Repository.create(new_config, store).manifest_hooks
61+
except InvalidManifestError as e:
62+
raise RepositoryCannotBeUpdatedError(six.text_type(e))
5763

5864
# See if any of our hooks were deleted with the new commits
5965
hooks = {hook['id'] for hook in repo_config['hooks']}
60-
hooks_missing = hooks - (hooks & set(new_repo.manifest_hooks))
66+
hooks_missing = hooks - set(new_hooks)
6167
if hooks_missing:
6268
raise RepositoryCannotBeUpdatedError(
6369
'Cannot update because the tip of master is missing these hooks:\n'

tests/commands/autoupdate_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ def test_autoupdate_tags_only(tagged_repo_with_more_commits, in_tmpdir, store):
260260
assert 'v1.2.3' in f.read()
261261

262262

263+
def test_autoupdate_latest_no_config(out_of_date_repo, in_tmpdir, store):
264+
config = make_config_from_repo(
265+
out_of_date_repo.path, rev=out_of_date_repo.original_rev,
266+
)
267+
write_config('.', config)
268+
269+
cmd_output('git', '-C', out_of_date_repo.path, 'rm', '-r', ':/')
270+
cmd_output('git', '-C', out_of_date_repo.path, 'commit', '-m', 'rm')
271+
272+
ret = autoupdate(Runner('.', C.CONFIG_FILE), store, tags_only=False)
273+
assert ret == 1
274+
with open(C.CONFIG_FILE) as f:
275+
assert out_of_date_repo.original_rev in f.read()
276+
277+
263278
@pytest.fixture
264279
def hook_disappearing_repo(tempdir_factory):
265280
path = make_repo(tempdir_factory, 'python_hooks_repo')

0 commit comments

Comments
 (0)