From 170175698809c8d324d36b064f8c2ddcd672d93f Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 11 Jun 2014 17:41:41 -0700 Subject: [PATCH] Don't add defaults when updating. --- pre_commit/commands.py | 7 +++++-- tests/commands_test.py | 17 ++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pre_commit/commands.py b/pre_commit/commands.py index a25e7830..9061b96a 100644 --- a/pre_commit/commands.py +++ b/pre_commit/commands.py @@ -90,7 +90,7 @@ def _update_repository(repo_config, runner): '{0}'.format(', '.join(sorted(hooks_missing))) ) - return remove_defaults([new_config], CONFIG_JSON_SCHEMA)[0] + return new_config def autoupdate(runner): @@ -130,7 +130,10 @@ def autoupdate(runner): if changed: with open(runner.config_file_path, 'w') as config_file: config_file.write( - ordered_dump(output_configs, **C.YAML_DUMP_KWARGS) + ordered_dump( + remove_defaults(output_configs, CONFIG_JSON_SCHEMA), + **C.YAML_DUMP_KWARGS + ) ) return retv diff --git a/tests/commands_test.py b/tests/commands_test.py index 3d8f32e2..b19f88b9 100644 --- a/tests/commands_test.py +++ b/tests/commands_test.py @@ -14,6 +14,7 @@ from pre_commit import commands from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA from pre_commit.clientlib.validate_config import validate_config_extra from pre_commit.jsonschema_extensions import apply_defaults +from pre_commit.jsonschema_extensions import remove_defaults from pre_commit.runner import Runner from testing.auto_namedtuple import auto_namedtuple from testing.util import get_head_sha @@ -68,7 +69,10 @@ def up_to_date_repo(python_hooks_repo): with open(os.path.join(python_hooks_repo, C.CONFIG_FILE), 'w') as file_obj: file_obj.write( - ordered_dump([config], **C.YAML_DUMP_KWARGS) + ordered_dump( + remove_defaults([config], CONFIG_JSON_SCHEMA), + **C.YAML_DUMP_KWARGS + ) ) yield auto_namedtuple( @@ -87,6 +91,7 @@ def test_up_to_date_repo(up_to_date_repo, runner_with_mocked_store): def test_autoupdate_up_to_date_repo(up_to_date_repo, mock_out_store_directory): before = open(C.CONFIG_FILE).read() + assert '^$' not in before runner = Runner(up_to_date_repo.python_hooks_repo) ret = commands.autoupdate(runner) after = open(C.CONFIG_FILE).read() @@ -126,14 +131,6 @@ def test_out_of_date_repo(out_of_date_repo, runner_with_mocked_store): assert ret['sha'] == out_of_date_repo.head_sha -def test_removes_defaults(out_of_date_repo, runner_with_mocked_store): - ret = commands._update_repository( - out_of_date_repo.repo_config, runner_with_mocked_store, - ) - assert 'args' not in ret['hooks'][0] - assert 'expected_return_value' not in ret['hooks'][0] - - def test_autoupdate_out_of_date_repo( out_of_date_repo, mock_out_store_directory ): @@ -143,6 +140,8 @@ def test_autoupdate_out_of_date_repo( after = open(C.CONFIG_FILE).read() assert ret == 0 assert before != after + # Make sure we don't add defaults + assert 'exclude' not in after assert out_of_date_repo.head_sha in after