Merge pull request #592 from pre-commit/remove_no_stash_allow_unstaged_config

Remove --no-stash and --allow-unstaged-config
This commit is contained in:
Anthony Sottile 2017-08-23 17:04:44 -04:00 committed by GitHub
commit 477c1163b7
4 changed files with 12 additions and 87 deletions

View file

@ -217,7 +217,7 @@ def _has_unstaged_config(runner):
def run(runner, args, environ=os.environ): def run(runner, args, environ=os.environ):
no_stash = args.no_stash or args.all_files or bool(args.files) no_stash = args.all_files or bool(args.files)
# Check if we have unresolved merge conflict files and fail fast. # Check if we have unresolved merge conflict files and fail fast.
if _has_unmerged_paths(runner): if _has_unmerged_paths(runner):
@ -227,18 +227,9 @@ def run(runner, args, environ=os.environ):
logger.error('Specify both --origin and --source.') logger.error('Specify both --origin and --source.')
return 1 return 1
if _has_unstaged_config(runner) and not no_stash: if _has_unstaged_config(runner) and not 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.',
)
else:
logger.error( logger.error(
'Your .pre-commit-config.yaml is unstaged.\n' 'Your .pre-commit-config.yaml is unstaged.\n'
'`git add .pre-commit-config.yaml` to fix this.\n' '`git add .pre-commit-config.yaml` to fix this.\n',
'Run pre-commit with --allow-unstaged-config to silence this.',
) )
return 1 return 1

View file

@ -135,10 +135,6 @@ def main(argv=None):
_add_color_option(run_parser) _add_color_option(run_parser)
_add_config_option(run_parser) _add_config_option(run_parser)
run_parser.add_argument('hook', nargs='?', help='A single hook-id to run') run_parser.add_argument('hook', nargs='?', help='A single hook-id to run')
run_parser.add_argument(
'--no-stash', default=False, action='store_true',
help='Use this option to prevent auto stashing of unstaged files.',
)
run_parser.add_argument( run_parser.add_argument(
'--verbose', '-v', action='store_true', default=False, '--verbose', '-v', action='store_true', default=False,
) )
@ -154,13 +150,6 @@ def main(argv=None):
'--commit-msg-filename', '--commit-msg-filename',
help='Filename to check when running during `commit-msg`', help='Filename to check when running during `commit-msg`',
) )
run_parser.add_argument(
'--allow-unstaged-config', default=False, action='store_true',
help=(
'Allow an unstaged config to be present. Note that this will '
'be stashed before parsing unless --no-stash is specified.'
),
)
run_parser.add_argument( run_parser.add_argument(
'--hook-stage', choices=('commit', 'push', 'commit-msg'), '--hook-stage', choices=('commit', 'push', 'commit-msg'),
default='commit', default='commit',
@ -173,7 +162,7 @@ def main(argv=None):
run_mutex_group = run_parser.add_mutually_exclusive_group(required=False) run_mutex_group = run_parser.add_mutually_exclusive_group(required=False)
run_mutex_group.add_argument( run_mutex_group.add_argument(
'--all-files', '-a', action='store_true', default=False, '--all-files', '-a', action='store_true', default=False,
help='Run on all the files in the repo. Implies --no-stash.', help='Run on all the files in the repo.',
) )
run_mutex_group.add_argument( run_mutex_group.add_argument(
'--files', nargs='*', default=[], '--files', nargs='*', default=[],

View file

@ -54,10 +54,8 @@ def _get_opts(
color=False, color=False,
verbose=False, verbose=False,
hook=None, hook=None,
no_stash=False,
origin='', origin='',
source='', source='',
allow_unstaged_config=False,
hook_stage='commit', hook_stage='commit',
show_diff_on_failure=False, show_diff_on_failure=False,
commit_msg_filename='', commit_msg_filename='',
@ -70,10 +68,8 @@ def _get_opts(
color=color, color=color,
verbose=verbose, verbose=verbose,
hook=hook, hook=hook,
no_stash=no_stash,
origin=origin, origin=origin,
source=source, source=source,
allow_unstaged_config=allow_unstaged_config,
hook_stage=hook_stage, hook_stage=hook_stage,
show_diff_on_failure=show_diff_on_failure, show_diff_on_failure=show_diff_on_failure,
commit_msg_filename=commit_msg_filename, commit_msg_filename=commit_msg_filename,
@ -332,38 +328,6 @@ def test_origin_source_error_msg(
assert warning_msg not in printed assert warning_msg not in printed
@pytest.mark.parametrize(
('no_stash', 'all_files', 'expect_stash'),
(
(True, True, False),
(True, False, False),
(False, True, False),
(False, False, True),
),
)
def test_no_stash(
cap_out,
repo_with_passing_hook,
no_stash,
all_files,
expect_stash,
mock_out_store_directory,
):
stage_a_file()
# Make unstaged changes
with open('foo.py', 'w') as foo_file:
foo_file.write('import os\n')
args = _get_opts(no_stash=no_stash, all_files=all_files)
ret, printed = _do_run(cap_out, repo_with_passing_hook, args)
assert ret == 0
warning_msg = b'[WARNING] Unstaged files detected.'
if expect_stash:
assert warning_msg in printed
else:
assert warning_msg not in printed
@pytest.mark.parametrize(('output', 'expected'), (('some', True), ('', False))) @pytest.mark.parametrize(('output', 'expected'), (('some', True), ('', False)))
def test_has_unmerged_paths(output, expected): def test_has_unmerged_paths(output, expected):
mock_runner = mock.Mock() mock_runner = mock.Mock()
@ -715,37 +679,19 @@ def modified_config_repo(repo_with_passing_hook):
yield repo_with_passing_hook yield repo_with_passing_hook
def test_allow_unstaged_config_option( def test_error_with_unstaged_config(
cap_out, modified_config_repo, mock_out_store_directory, cap_out, modified_config_repo, mock_out_store_directory,
): ):
args = _get_opts(allow_unstaged_config=True) args = _get_opts()
ret, printed = _do_run(cap_out, modified_config_repo, args)
expected = (
b'You have an unstaged config file and have specified the '
b'--allow-unstaged-config option.'
)
assert expected in printed
assert ret == 0
def test_no_allow_unstaged_config_option(
cap_out, modified_config_repo, mock_out_store_directory,
):
args = _get_opts(allow_unstaged_config=False)
ret, printed = _do_run(cap_out, modified_config_repo, args) 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-config.yaml is unstaged.' in printed
assert ret == 1 assert ret == 1
@pytest.mark.parametrize( @pytest.mark.parametrize(
'opts', 'opts', ({'all_files': True}, {'files': [C.CONFIG_FILE]}),
(
{'allow_unstaged_config': False, 'no_stash': True},
{'all_files': True},
{'files': [C.CONFIG_FILE]},
),
) )
def test_unstaged_message_suppressed( def test_no_unstaged_error_with_all_files_or_files(
cap_out, modified_config_repo, mock_out_store_directory, opts, cap_out, modified_config_repo, mock_out_store_directory, opts,
): ):
args = _get_opts(**opts) args = _get_opts(**opts)

View file

@ -137,8 +137,7 @@ def test_get_conflicted_files_in_submodule(in_conflicting_submodule):
def test_get_conflicted_files_unstaged_files(in_merge_conflict): def test_get_conflicted_files_unstaged_files(in_merge_conflict):
# If they for whatever reason did pre-commit run --no-stash during a """This case no longer occurs, but it is a useful test nonetheless"""
# conflict
resolve_conflict() resolve_conflict()
# Make unstaged file. # Make unstaged file.