mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #857 from runz0rd/master
Reraises InvalidManifestError as RepositoryCannotBeUpdatedError
This commit is contained in:
commit
dc84f21dd4
2 changed files with 23 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
||||||
import re
|
import re
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
import six
|
||||||
from aspy.yaml import ordered_dump
|
from aspy.yaml import ordered_dump
|
||||||
from aspy.yaml import ordered_load
|
from aspy.yaml import ordered_load
|
||||||
from cfgv import remove_defaults
|
from cfgv import remove_defaults
|
||||||
|
|
@ -11,6 +12,7 @@ from cfgv import remove_defaults
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
from pre_commit import output
|
from pre_commit import output
|
||||||
from pre_commit.clientlib import CONFIG_SCHEMA
|
from pre_commit.clientlib import CONFIG_SCHEMA
|
||||||
|
from pre_commit.clientlib import InvalidManifestError
|
||||||
from pre_commit.clientlib import is_local_repo
|
from pre_commit.clientlib import is_local_repo
|
||||||
from pre_commit.clientlib import is_meta_repo
|
from pre_commit.clientlib import is_meta_repo
|
||||||
from pre_commit.clientlib import load_config
|
from pre_commit.clientlib import load_config
|
||||||
|
|
@ -53,11 +55,15 @@ def _update_repo(repo_config, store, tags_only):
|
||||||
# Construct a new config with the head rev
|
# Construct a new config with the head rev
|
||||||
new_config = OrderedDict(repo_config)
|
new_config = OrderedDict(repo_config)
|
||||||
new_config['rev'] = rev
|
new_config['rev'] = rev
|
||||||
new_repo = Repository.create(new_config, store)
|
|
||||||
|
try:
|
||||||
|
new_hooks = Repository.create(new_config, store).manifest_hooks
|
||||||
|
except InvalidManifestError as e:
|
||||||
|
raise RepositoryCannotBeUpdatedError(six.text_type(e))
|
||||||
|
|
||||||
# See if any of our hooks were deleted with the new commits
|
# See if any of our hooks were deleted with the new commits
|
||||||
hooks = {hook['id'] for hook in repo_config['hooks']}
|
hooks = {hook['id'] for hook in repo_config['hooks']}
|
||||||
hooks_missing = hooks - (hooks & set(new_repo.manifest_hooks))
|
hooks_missing = hooks - set(new_hooks)
|
||||||
if hooks_missing:
|
if hooks_missing:
|
||||||
raise RepositoryCannotBeUpdatedError(
|
raise RepositoryCannotBeUpdatedError(
|
||||||
'Cannot update because the tip of master is missing these hooks:\n'
|
'Cannot update because the tip of master is missing these hooks:\n'
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,21 @@ def test_autoupdate_tags_only(tagged_repo_with_more_commits, in_tmpdir, store):
|
||||||
assert 'v1.2.3' in f.read()
|
assert 'v1.2.3' in f.read()
|
||||||
|
|
||||||
|
|
||||||
|
def test_autoupdate_latest_no_config(out_of_date_repo, in_tmpdir, store):
|
||||||
|
config = make_config_from_repo(
|
||||||
|
out_of_date_repo.path, rev=out_of_date_repo.original_rev,
|
||||||
|
)
|
||||||
|
write_config('.', config)
|
||||||
|
|
||||||
|
cmd_output('git', '-C', out_of_date_repo.path, 'rm', '-r', ':/')
|
||||||
|
cmd_output('git', '-C', out_of_date_repo.path, 'commit', '-m', 'rm')
|
||||||
|
|
||||||
|
ret = autoupdate(Runner('.', C.CONFIG_FILE), store, tags_only=False)
|
||||||
|
assert ret == 1
|
||||||
|
with open(C.CONFIG_FILE) as f:
|
||||||
|
assert out_of_date_repo.original_rev in f.read()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hook_disappearing_repo(tempdir_factory):
|
def hook_disappearing_repo(tempdir_factory):
|
||||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue