mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #244 from pre-commit/allow_unstaged_config_for_all_files_242
Allow unstaged config when running against files or all-files. Resolves #242
This commit is contained in:
commit
2c70476c63
2 changed files with 29 additions and 12 deletions
|
|
@ -139,6 +139,7 @@ def _has_unstaged_config(runner):
|
||||||
|
|
||||||
|
|
||||||
def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
|
def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
|
||||||
|
no_stash = args.no_stash or args.all_files or bool(args.files)
|
||||||
# Set up our logging handler
|
# Set up our logging handler
|
||||||
logger.addHandler(LoggingHandler(args.color, write=write))
|
logger.addHandler(LoggingHandler(args.color, write=write))
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
@ -150,7 +151,7 @@ def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
|
||||||
if bool(args.source) != bool(args.origin):
|
if bool(args.source) != bool(args.origin):
|
||||||
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 args.no_stash:
|
if _has_unstaged_config(runner) and not no_stash:
|
||||||
if args.allow_unstaged_config:
|
if args.allow_unstaged_config:
|
||||||
logger.warn(
|
logger.warn(
|
||||||
'You have an unstaged config file and have specified the '
|
'You have an unstaged config file and have specified the '
|
||||||
|
|
@ -166,8 +167,7 @@ def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
|
||||||
)
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# Don't stash if specified or files are specified
|
if no_stash:
|
||||||
if args.no_stash or args.all_files or args.files:
|
|
||||||
ctx = noop_context()
|
ctx = noop_context()
|
||||||
else:
|
else:
|
||||||
ctx = staged_files_only(runner.cmd_runner)
|
ctx = staged_files_only(runner.cmd_runner)
|
||||||
|
|
|
||||||
|
|
@ -433,14 +433,17 @@ def test_allow_unstaged_config_option(
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
|
||||||
def test_no_allow_unstaged_config_option(
|
def modify_config(path):
|
||||||
repo_with_passing_hook, mock_out_store_directory,
|
with cwd(path):
|
||||||
):
|
|
||||||
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
|
# writing a newline should be relatively harmless to get a change
|
||||||
config_file.write('\n')
|
config_file.write('\n')
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_allow_unstaged_config_option(
|
||||||
|
repo_with_passing_hook, mock_out_store_directory,
|
||||||
|
):
|
||||||
|
modify_config(repo_with_passing_hook)
|
||||||
args = _get_opts(allow_unstaged_config=False)
|
args = _get_opts(allow_unstaged_config=False)
|
||||||
ret, printed = _do_run(repo_with_passing_hook, args)
|
ret, printed = _do_run(repo_with_passing_hook, args)
|
||||||
assert 'Your .pre-commit-config.yaml is unstaged.' in printed
|
assert 'Your .pre-commit-config.yaml is unstaged.' in printed
|
||||||
|
|
@ -450,11 +453,25 @@ def test_no_allow_unstaged_config_option(
|
||||||
def test_no_stash_suppresses_allow_unstaged_config_option(
|
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):
|
modify_config(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)
|
args = _get_opts(allow_unstaged_config=False, no_stash=True)
|
||||||
ret, printed = _do_run(repo_with_passing_hook, args)
|
ret, printed = _do_run(repo_with_passing_hook, args)
|
||||||
assert 'Your .pre-commit-config.yaml is unstaged.' not in printed
|
assert 'Your .pre-commit-config.yaml is unstaged.' not in printed
|
||||||
|
|
||||||
|
|
||||||
|
def test_all_files_suppresses_allow_unstaged_config_option(
|
||||||
|
repo_with_passing_hook, mock_out_store_directory,
|
||||||
|
):
|
||||||
|
modify_config(repo_with_passing_hook)
|
||||||
|
args = _get_opts(all_files=True)
|
||||||
|
ret, printed = _do_run(repo_with_passing_hook, args)
|
||||||
|
assert 'Your .pre-commit-config.yaml is unstaged.' not in printed
|
||||||
|
|
||||||
|
|
||||||
|
def test_files_suppresses_allow_unstaged_config_option(
|
||||||
|
repo_with_passing_hook, mock_out_store_directory,
|
||||||
|
):
|
||||||
|
modify_config(repo_with_passing_hook)
|
||||||
|
args = _get_opts(files=['.pre-commit-config.yaml'])
|
||||||
|
ret, printed = _do_run(repo_with_passing_hook, args)
|
||||||
|
assert 'Your .pre-commit-config.yaml is unstaged.' not in printed
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue