mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
add helpful message and test
This commit is contained in:
parent
03ac3b0840
commit
71a740d65d
2 changed files with 36 additions and 4 deletions
|
|
@ -215,6 +215,13 @@ def _run_hooks(config, hooks, args, environ):
|
||||||
if retval and config['fail_fast']:
|
if retval and config['fail_fast']:
|
||||||
break
|
break
|
||||||
if retval and args.show_diff_on_failure and git.has_diff():
|
if retval and args.show_diff_on_failure and git.has_diff():
|
||||||
|
if args.all_files:
|
||||||
|
output.write_line(
|
||||||
|
'Pre-commit hook(s) made changes. '
|
||||||
|
'If you are seeing this message on CI,'
|
||||||
|
' reproduce locally with: pre-commit run --all-files',
|
||||||
|
)
|
||||||
|
else:
|
||||||
output.write_line('All changes made by hooks:')
|
output.write_line('All changes made by hooks:')
|
||||||
subprocess.call(('git', '--no-pager', 'diff', '--no-ext-diff'))
|
subprocess.call(('git', '--no-pager', 'diff', '--no-ext-diff'))
|
||||||
return retval
|
return retval
|
||||||
|
|
|
||||||
|
|
@ -178,16 +178,41 @@ def test_global_exclude(cap_out, store, tempdir_factory):
|
||||||
assert printed.endswith(expected)
|
assert printed.endswith(expected)
|
||||||
|
|
||||||
|
|
||||||
def test_show_diff_on_failure(capfd, cap_out, store, tempdir_factory):
|
@pytest.mark.parametrize(
|
||||||
|
('args', 'expected_out'),
|
||||||
|
[
|
||||||
|
(
|
||||||
|
{
|
||||||
|
'show_diff_on_failure': True,
|
||||||
|
},
|
||||||
|
b'All changes made by hooks:',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{
|
||||||
|
'show_diff_on_failure': True,
|
||||||
|
'all_files': True,
|
||||||
|
},
|
||||||
|
b'reproduce locally with: pre-commit run --all-files',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_show_diff_on_failure(
|
||||||
|
args,
|
||||||
|
expected_out,
|
||||||
|
capfd,
|
||||||
|
cap_out,
|
||||||
|
store,
|
||||||
|
tempdir_factory,
|
||||||
|
):
|
||||||
git_path = make_consuming_repo(
|
git_path = make_consuming_repo(
|
||||||
tempdir_factory, 'modified_file_returns_zero_repo',
|
tempdir_factory, 'modified_file_returns_zero_repo',
|
||||||
)
|
)
|
||||||
with cwd(git_path):
|
with cwd(git_path):
|
||||||
stage_a_file('bar.py')
|
stage_a_file('bar.py')
|
||||||
_test_run(
|
_test_run(
|
||||||
cap_out, store, git_path, {'show_diff_on_failure': True},
|
cap_out, store, git_path, args,
|
||||||
# we're only testing the output after running
|
# we're only testing the output after running
|
||||||
(), 1, True,
|
expected_out, 1, True,
|
||||||
)
|
)
|
||||||
out, _ = capfd.readouterr()
|
out, _ = capfd.readouterr()
|
||||||
assert 'diff --git' in out
|
assert 'diff --git' in out
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue