From 1c97d3f5fde3804ded59f65ef8f12ea429638c4d Mon Sep 17 00:00:00 2001 From: Milos Pejanovic Date: Wed, 31 Oct 2018 17:39:47 +0100 Subject: [PATCH 1/4] Added a try except block which reraises InvalidManifestError as RepositoryCannotBeUpdatedError --- pre_commit/commands/autoupdate.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py index 8f3714c4..d08ea411 100644 --- a/pre_commit/commands/autoupdate.py +++ b/pre_commit/commands/autoupdate.py @@ -14,6 +14,7 @@ from pre_commit.clientlib import CONFIG_SCHEMA from pre_commit.clientlib import is_local_repo from pre_commit.clientlib import is_meta_repo from pre_commit.clientlib import load_config +from pre_commit.clientlib import InvalidManifestError from pre_commit.commands.migrate_config import migrate_config from pre_commit.repository import Repository from pre_commit.util import CalledProcessError @@ -57,7 +58,10 @@ def _update_repo(repo_config, store, tags_only): # See if any of our hooks were deleted with the new commits hooks = {hook['id'] for hook in repo_config['hooks']} - hooks_missing = hooks - (hooks & set(new_repo.manifest_hooks)) + try: + hooks_missing = hooks - (hooks & set(new_repo.manifest_hooks)) + except InvalidManifestError as e: + raise RepositoryCannotBeUpdatedError(e.args[0]) if hooks_missing: raise RepositoryCannotBeUpdatedError( 'Cannot update because the tip of master is missing these hooks:\n' From bf8c8521cdf26006eff64bb2d4a35b77dcb0667a Mon Sep 17 00:00:00 2001 From: Milos Pejanovic Date: Wed, 14 Nov 2018 00:43:04 +0100 Subject: [PATCH 2/4] Added a test and small change for error output --- pre_commit/commands/autoupdate.py | 2 +- tests/commands/autoupdate_test.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py index d08ea411..a02efe08 100644 --- a/pre_commit/commands/autoupdate.py +++ b/pre_commit/commands/autoupdate.py @@ -132,7 +132,7 @@ def autoupdate(runner, store, tags_only, repos=()): try: new_repo_config = _update_repo(repo_config, store, tags_only) except RepositoryCannotBeUpdatedError as error: - output.write_line(error.args[0]) + output.write_line(str(error)) output_repos.append(repo_config) retv = 1 continue diff --git a/tests/commands/autoupdate_test.py b/tests/commands/autoupdate_test.py index 3bfb62e0..b6e81b2a 100644 --- a/tests/commands/autoupdate_test.py +++ b/tests/commands/autoupdate_test.py @@ -260,6 +260,21 @@ def test_autoupdate_tags_only(tagged_repo_with_more_commits, in_tmpdir, store): 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 def hook_disappearing_repo(tempdir_factory): path = make_repo(tempdir_factory, 'python_hooks_repo') From e339de22d76b714130d797a80097e9ef13ef0543 Mon Sep 17 00:00:00 2001 From: Milos Pejanovic Date: Wed, 14 Nov 2018 01:59:18 +0100 Subject: [PATCH 3/4] Added requested changes --- pre_commit/commands/autoupdate.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py index a02efe08..0bff116c 100644 --- a/pre_commit/commands/autoupdate.py +++ b/pre_commit/commands/autoupdate.py @@ -11,10 +11,10 @@ from cfgv import remove_defaults import pre_commit.constants as C from pre_commit import output 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_meta_repo from pre_commit.clientlib import load_config -from pre_commit.clientlib import InvalidManifestError from pre_commit.commands.migrate_config import migrate_config from pre_commit.repository import Repository from pre_commit.util import CalledProcessError @@ -54,14 +54,15 @@ def _update_repo(repo_config, store, tags_only): # Construct a new config with the head rev new_config = OrderedDict(repo_config) 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(e.args[0]) # See if any of our hooks were deleted with the new commits hooks = {hook['id'] for hook in repo_config['hooks']} - try: - hooks_missing = hooks - (hooks & set(new_repo.manifest_hooks)) - except InvalidManifestError as e: - raise RepositoryCannotBeUpdatedError(e.args[0]) + hooks_missing = hooks - set(new_hooks) if hooks_missing: raise RepositoryCannotBeUpdatedError( 'Cannot update because the tip of master is missing these hooks:\n' From aaa3976a29c1e4099029adaabebe2b076a3ad052 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 13 Nov 2018 17:23:32 -0800 Subject: [PATCH 4/4] Use text_type instead of str() --- pre_commit/commands/autoupdate.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py index 0bff116c..d93d7e11 100644 --- a/pre_commit/commands/autoupdate.py +++ b/pre_commit/commands/autoupdate.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import re from collections import OrderedDict +import six from aspy.yaml import ordered_dump from aspy.yaml import ordered_load from cfgv import remove_defaults @@ -58,7 +59,7 @@ def _update_repo(repo_config, store, tags_only): try: new_hooks = Repository.create(new_config, store).manifest_hooks except InvalidManifestError as e: - raise RepositoryCannotBeUpdatedError(e.args[0]) + raise RepositoryCannotBeUpdatedError(six.text_type(e)) # See if any of our hooks were deleted with the new commits hooks = {hook['id'] for hook in repo_config['hooks']} @@ -133,7 +134,7 @@ def autoupdate(runner, store, tags_only, repos=()): try: new_repo_config = _update_repo(repo_config, store, tags_only) except RepositoryCannotBeUpdatedError as error: - output.write_line(str(error)) + output.write_line(error.args[0]) output_repos.append(repo_config) retv = 1 continue