mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-05-04 14:29:14 -05:00
fix for #157
This commit is contained in:
@@ -53,6 +53,7 @@ def _get_opts(
|
||||
no_stash=False,
|
||||
origin='',
|
||||
source='',
|
||||
allow_unstaged_config=False,
|
||||
):
|
||||
# These are mutually exclusive
|
||||
assert not (all_files and files)
|
||||
@@ -65,6 +66,7 @@ def _get_opts(
|
||||
no_stash=no_stash,
|
||||
origin=origin,
|
||||
source=source,
|
||||
allow_unstaged_config=allow_unstaged_config,
|
||||
)
|
||||
|
||||
|
||||
@@ -334,3 +336,60 @@ def test_lots_of_files(mock_out_store_directory, tmpdir_factory):
|
||||
stderr=subprocess.STDOUT,
|
||||
env=env,
|
||||
)
|
||||
|
||||
|
||||
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:
|
||||
# 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 ret == 0
|
||||
|
||||
|
||||
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:
|
||||
# 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 ret == 1
|
||||
|
||||
|
||||
def test_no_stash_suppresses_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:
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user