From a875231be3b89c1803237a336e3b11b60d8ddc9b Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 10 May 2015 17:00:23 -0700 Subject: [PATCH] Fixup --- pre_commit/commands/run.py | 24 ++++++++++---------- tests/commands/run_test.py | 45 +++++++++++++------------------------- 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 4913069e..66bc43b7 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -130,12 +130,9 @@ def _has_unmerged_paths(runner): def _has_unstaged_config(runner): - retcode, stdout, stderr = runner.cmd_runner.run( - [ - 'git', 'diff', '--exit-code', runner.config_file_path - ], + retcode, _, _ = runner.cmd_runner.run( + ('git', 'diff', '--exit-code', runner.config_file_path), retcode=None, - encoding=None, ) # be explicit, other git errors don't mean it has an unstaged config. return retcode == 1 @@ -155,13 +152,18 @@ def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ): return 1 if _has_unstaged_config(runner) and not args.no_stash: if args.allow_unstaged_config: - logger.warn('You have an unstaged config file and have ' - 'specified the --allow-unstaged-config option.\n' - 'Note that your config will be stashed before the ' - 'config is parsed unless --no-stash is specified.') + logger.warn( + 'You have an unstaged config file and have specified the ' + '--allow-unstaged-config option.\n' + 'Note that your config will be stashed before the config is ' + 'parsed unless --no-stash is specified.', + ) else: - logger.error('You have an unstaged config file and have not ' - 'specified the --allow-unstaged-config option.\n') + logger.error( + 'Your .pre-commit-config.yaml is unstaged.\n' + '`git add .pre-commit-config.yaml` to fix this.\n' + 'Run pre-commit with --allow-unstaged-config to silence this.' + ) return 1 # Don't stash if specified or files are specified diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py index 801183ce..f907eed9 100644 --- a/tests/commands/run_test.py +++ b/tests/commands/run_test.py @@ -401,58 +401,43 @@ def test_local_hook_fails( ) -def test_allow_unstaged_config_option(repo_with_passing_hook, - mock_out_store_directory): - +def test_allow_unstaged_config_option( + repo_with_passing_hook, mock_out_store_directory, +): with cwd(repo_with_passing_hook): - with io.open( - '.pre-commit-config.yaml', 'a+', - ) as config_file: + with io.open('.pre-commit-config.yaml', 'a+') as config_file: # writing a newline should be relatively harmless to get a change config_file.write('\n') args = _get_opts(allow_unstaged_config=True) ret, printed = _do_run(repo_with_passing_hook, args) - common_msg = 'You have an unstaged config file' - warning_msg = 'have specified the --allow-unstaged-config option.' - - assert common_msg in printed - assert warning_msg in printed + assert 'You have an unstaged config file' in printed + assert 'have specified the --allow-unstaged-config option.' in printed assert ret == 0 -def test_no_allow_unstaged_config_option(repo_with_passing_hook, - mock_out_store_directory): - +def test_no_allow_unstaged_config_option( + repo_with_passing_hook, mock_out_store_directory, +): with cwd(repo_with_passing_hook): - with io.open( - '.pre-commit-config.yaml', 'a+', - ) as config_file: + with io.open('.pre-commit-config.yaml', 'a+') as config_file: # writing a newline should be relatively harmless to get a change config_file.write('\n') args = _get_opts(allow_unstaged_config=False) ret, printed = _do_run(repo_with_passing_hook, args) - common_msg = 'You have an unstaged config file' - error_msg = 'have not specified the --allow-unstaged-config option.\n' - - assert common_msg in printed - assert error_msg in printed + assert 'Your .pre-commit-config.yaml is unstaged.' in printed assert ret == 1 def test_no_stash_suppresses_allow_unstaged_config_option( - repo_with_passing_hook, mock_out_store_directory): - + repo_with_passing_hook, mock_out_store_directory, +): with cwd(repo_with_passing_hook): - with io.open( - '.pre-commit-config.yaml', 'a+', - ) as config_file: + with io.open('.pre-commit-config.yaml', 'a+') as config_file: # writing a newline should be relatively harmless to get a change config_file.write('\n') args = _get_opts(allow_unstaged_config=False, no_stash=True) ret, printed = _do_run(repo_with_passing_hook, args) - common_msg = 'You have an unstaged config file' - - assert common_msg not in printed + assert 'Your .pre-commit-config.yaml is unstaged.' not in printed