From 8407b92b18f92b7c012d913e4de760d41efe2c31 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei Date: Tue, 9 Jan 2018 17:51:41 +0200 Subject: [PATCH 1/4] Replace string literals with constants --- pre_commit/commands/run.py | 9 +++++---- pre_commit/main.py | 2 +- pre_commit/repository.py | 4 ++-- testing/fixtures.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 3a08c8d8..71fb43e7 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -9,6 +9,7 @@ import sys from identify.identify import tags_from_path +import pre_commit.constants as C from pre_commit import color from pre_commit import git from pre_commit import output @@ -222,10 +223,10 @@ def run(runner, args, environ=os.environ): logger.error('Specify both --origin and --source.') return 1 if _has_unstaged_config(runner) and not no_stash: - logger.error( - 'Your .pre-commit-config.yaml is unstaged.\n' - '`git add .pre-commit-config.yaml` to fix this.', - ) + logger.error(( + 'Your {0} is unstaged.\n' + '`git add {0}` to fix this.' + ).format(C.CONFIG_FILE),) return 1 # Expose origin / source as environment variables for hooks to consume diff --git a/pre_commit/main.py b/pre_commit/main.py index 4c9202ad..865571a5 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -42,7 +42,7 @@ def _add_color_option(parser): def _add_config_option(parser): parser.add_argument( - '-c', '--config', default='.pre-commit-config.yaml', + '-c', '--config', default=C.CONFIG_FILE, help='Path to alternate config file', ) diff --git a/pre_commit/repository.py b/pre_commit/repository.py index bc0ecad3..5c11921c 100644 --- a/pre_commit/repository.py +++ b/pre_commit/repository.py @@ -269,14 +269,14 @@ class MetaRepository(LocalRepository): { 'id': 'check-hooks-apply', 'name': 'Check hooks apply to the repository', - 'files': '.pre-commit-config.yaml', + 'files': C.CONFIG_FILE, 'language': 'system', 'entry': _make_entry(check_hooks_apply), }, { 'id': 'check-useless-excludes', 'name': 'Check for useless excludes', - 'files': '.pre-commit-config.yaml', + 'files': C.CONFIG_FILE, 'language': 'system', 'entry': _make_entry(check_useless_excludes), }, diff --git a/testing/fixtures.py b/testing/fixtures.py index b1c7a89f..edb1bcdf 100644 --- a/testing/fixtures.py +++ b/testing/fixtures.py @@ -47,7 +47,7 @@ def modify_manifest(path): with io.open(manifest_path, 'w') as manifest_file: manifest_file.write(ordered_dump(manifest, **C.YAML_DUMP_KWARGS)) cmd_output( - 'git', 'commit', '-am', 'update .pre-commit-hooks.yaml', cwd=path, + 'git', 'commit', '-am', 'update {}'.format(C.MANIFEST_FILE), cwd=path, ) From 81df782c2067b5eeb1bbf6dce991b6bb30f7e4e4 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei <6d0847b9@opayq.com> Date: Tue, 9 Jan 2018 18:10:05 +0200 Subject: [PATCH 2/4] Update unstaged config file error message --- pre_commit/commands/run.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 71fb43e7..4df2e30e 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -223,10 +223,10 @@ def run(runner, args, environ=os.environ): logger.error('Specify both --origin and --source.') return 1 if _has_unstaged_config(runner) and not no_stash: - logger.error(( - 'Your {0} is unstaged.\n' - '`git add {0}` to fix this.' - ).format(C.CONFIG_FILE),) + logger.error( + 'Your pre-commit configuration is unstaged.\n' + '`git add {}` to fix this.'.format(runner.config_file), + ) return 1 # Expose origin / source as environment variables for hooks to consume From 2255d8484e57d8067769a8de2e581af1371140c4 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 9 Jan 2018 08:15:27 -0800 Subject: [PATCH 3/4] Update message for unstaged config in test --- tests/commands/run_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py index 336222d6..97c82c25 100644 --- a/tests/commands/run_test.py +++ b/tests/commands/run_test.py @@ -683,7 +683,7 @@ def test_error_with_unstaged_config( ): args = run_opts() ret, printed = _do_run(cap_out, modified_config_repo, args) - assert b'Your .pre-commit-config.yaml is unstaged.' in printed + assert b'Your pre-commit configuration is unstaged.' in printed assert ret == 1 @@ -695,7 +695,7 @@ def test_no_unstaged_error_with_all_files_or_files( ): args = run_opts(**opts) ret, printed = _do_run(cap_out, modified_config_repo, args) - assert b'Your .pre-commit-config.yaml is unstaged.' not in printed + assert b'Your pre-commit configuration is unstaged.' not in printed def test_files_running_subdir( From df38e1010bc587ed3a046131f6c3b91fa0d6fed3 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 9 Jan 2018 08:49:42 -0800 Subject: [PATCH 4/4] Remove unused import --- pre_commit/commands/run.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 4df2e30e..c70eff01 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -9,7 +9,6 @@ import sys from identify.identify import tags_from_path -import pre_commit.constants as C from pre_commit import color from pre_commit import git from pre_commit import output