Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 477c116

Browse files
authored
Merge pull request #592 from pre-commit/remove_no_stash_allow_unstaged_config
Remove --no-stash and --allow-unstaged-config
2 parents 7139a47 + 6793fd8 commit 477c116

4 files changed

Lines changed: 12 additions & 87 deletions

File tree

pre_commit/commands/run.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def _has_unstaged_config(runner):
217217

218218

219219
def run(runner, args, environ=os.environ):
220-
no_stash = args.no_stash or args.all_files or bool(args.files)
220+
no_stash = args.all_files or bool(args.files)
221221

222222
# Check if we have unresolved merge conflict files and fail fast.
223223
if _has_unmerged_paths(runner):
@@ -227,20 +227,11 @@ def run(runner, args, environ=os.environ):
227227
logger.error('Specify both --origin and --source.')
228228
return 1
229229
if _has_unstaged_config(runner) and not no_stash:
230-
if args.allow_unstaged_config:
231-
logger.warn(
232-
'You have an unstaged config file and have specified the '
233-
'--allow-unstaged-config option.\n'
234-
'Note that your config will be stashed before the config is '
235-
'parsed unless --no-stash is specified.',
236-
)
237-
else:
238-
logger.error(
239-
'Your .pre-commit-config.yaml is unstaged.\n'
240-
'`git add .pre-commit-config.yaml` to fix this.\n'
241-
'Run pre-commit with --allow-unstaged-config to silence this.',
242-
)
243-
return 1
230+
logger.error(
231+
'Your .pre-commit-config.yaml is unstaged.\n'
232+
'`git add .pre-commit-config.yaml` to fix this.\n',
233+
)
234+
return 1
244235

245236
# Expose origin / source as environment variables for hooks to consume
246237
if args.origin and args.source:

pre_commit/main.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ def main(argv=None):
135135
_add_color_option(run_parser)
136136
_add_config_option(run_parser)
137137
run_parser.add_argument('hook', nargs='?', help='A single hook-id to run')
138-
run_parser.add_argument(
139-
'--no-stash', default=False, action='store_true',
140-
help='Use this option to prevent auto stashing of unstaged files.',
141-
)
142138
run_parser.add_argument(
143139
'--verbose', '-v', action='store_true', default=False,
144140
)
@@ -154,13 +150,6 @@ def main(argv=None):
154150
'--commit-msg-filename',
155151
help='Filename to check when running during `commit-msg`',
156152
)
157-
run_parser.add_argument(
158-
'--allow-unstaged-config', default=False, action='store_true',
159-
help=(
160-
'Allow an unstaged config to be present. Note that this will '
161-
'be stashed before parsing unless --no-stash is specified.'
162-
),
163-
)
164153
run_parser.add_argument(
165154
'--hook-stage', choices=('commit', 'push', 'commit-msg'),
166155
default='commit',
@@ -173,7 +162,7 @@ def main(argv=None):
173162
run_mutex_group = run_parser.add_mutually_exclusive_group(required=False)
174163
run_mutex_group.add_argument(
175164
'--all-files', '-a', action='store_true', default=False,
176-
help='Run on all the files in the repo. Implies --no-stash.',
165+
help='Run on all the files in the repo.',
177166
)
178167
run_mutex_group.add_argument(
179168
'--files', nargs='*', default=[],

tests/commands/run_test.py

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ def _get_opts(
5454
color=False,
5555
verbose=False,
5656
hook=None,
57-
no_stash=False,
5857
origin='',
5958
source='',
60-
allow_unstaged_config=False,
6159
hook_stage='commit',
6260
show_diff_on_failure=False,
6361
commit_msg_filename='',
@@ -70,10 +68,8 @@ def _get_opts(
7068
color=color,
7169
verbose=verbose,
7270
hook=hook,
73-
no_stash=no_stash,
7471
origin=origin,
7572
source=source,
76-
allow_unstaged_config=allow_unstaged_config,
7773
hook_stage=hook_stage,
7874
show_diff_on_failure=show_diff_on_failure,
7975
commit_msg_filename=commit_msg_filename,
@@ -332,38 +328,6 @@ def test_origin_source_error_msg(
332328
assert warning_msg not in printed
333329

334330

335-
@pytest.mark.parametrize(
336-
('no_stash', 'all_files', 'expect_stash'),
337-
(
338-
(True, True, False),
339-
(True, False, False),
340-
(False, True, False),
341-
(False, False, True),
342-
),
343-
)
344-
def test_no_stash(
345-
cap_out,
346-
repo_with_passing_hook,
347-
no_stash,
348-
all_files,
349-
expect_stash,
350-
mock_out_store_directory,
351-
):
352-
stage_a_file()
353-
# Make unstaged changes
354-
with open('foo.py', 'w') as foo_file:
355-
foo_file.write('import os\n')
356-
357-
args = _get_opts(no_stash=no_stash, all_files=all_files)
358-
ret, printed = _do_run(cap_out, repo_with_passing_hook, args)
359-
assert ret == 0
360-
warning_msg = b'[WARNING] Unstaged files detected.'
361-
if expect_stash:
362-
assert warning_msg in printed
363-
else:
364-
assert warning_msg not in printed
365-
366-
367331
@pytest.mark.parametrize(('output', 'expected'), (('some', True), ('', False)))
368332
def test_has_unmerged_paths(output, expected):
369333
mock_runner = mock.Mock()
@@ -715,37 +679,19 @@ def modified_config_repo(repo_with_passing_hook):
715679
yield repo_with_passing_hook
716680

717681

718-
def test_allow_unstaged_config_option(
682+
def test_error_with_unstaged_config(
719683
cap_out, modified_config_repo, mock_out_store_directory,
720684
):
721-
args = _get_opts(allow_unstaged_config=True)
722-
ret, printed = _do_run(cap_out, modified_config_repo, args)
723-
expected = (
724-
b'You have an unstaged config file and have specified the '
725-
b'--allow-unstaged-config option.'
726-
)
727-
assert expected in printed
728-
assert ret == 0
729-
730-
731-
def test_no_allow_unstaged_config_option(
732-
cap_out, modified_config_repo, mock_out_store_directory,
733-
):
734-
args = _get_opts(allow_unstaged_config=False)
685+
args = _get_opts()
735686
ret, printed = _do_run(cap_out, modified_config_repo, args)
736687
assert b'Your .pre-commit-config.yaml is unstaged.' in printed
737688
assert ret == 1
738689

739690

740691
@pytest.mark.parametrize(
741-
'opts',
742-
(
743-
{'allow_unstaged_config': False, 'no_stash': True},
744-
{'all_files': True},
745-
{'files': [C.CONFIG_FILE]},
746-
),
692+
'opts', ({'all_files': True}, {'files': [C.CONFIG_FILE]}),
747693
)
748-
def test_unstaged_message_suppressed(
694+
def test_no_unstaged_error_with_all_files_or_files(
749695
cap_out, modified_config_repo, mock_out_store_directory, opts,
750696
):
751697
args = _get_opts(**opts)

tests/git_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ def test_get_conflicted_files_in_submodule(in_conflicting_submodule):
137137

138138

139139
def test_get_conflicted_files_unstaged_files(in_merge_conflict):
140-
# If they for whatever reason did pre-commit run --no-stash during a
141-
# conflict
140+
"""This case no longer occurs, but it is a useful test nonetheless"""
142141
resolve_conflict()
143142

144143
# Make unstaged file.

0 commit comments

Comments
 (0)