mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 20:40:08 -06:00
add helpful message and test
This commit is contained in:
committed by
Anthony Sottile
parent
03ac3b0840
commit
71a740d65d
@@ -215,7 +215,14 @@ def _run_hooks(config, hooks, args, environ):
|
||||
if retval and config['fail_fast']:
|
||||
break
|
||||
if retval and args.show_diff_on_failure and git.has_diff():
|
||||
output.write_line('All changes made by hooks:')
|
||||
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:')
|
||||
subprocess.call(('git', '--no-pager', 'diff', '--no-ext-diff'))
|
||||
return retval
|
||||
|
||||
|
||||
@@ -178,16 +178,41 @@ def test_global_exclude(cap_out, store, tempdir_factory):
|
||||
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(
|
||||
tempdir_factory, 'modified_file_returns_zero_repo',
|
||||
)
|
||||
with cwd(git_path):
|
||||
stage_a_file('bar.py')
|
||||
_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
|
||||
(), 1, True,
|
||||
expected_out, 1, True,
|
||||
)
|
||||
out, _ = capfd.readouterr()
|
||||
assert 'diff --git' in out
|
||||
|
||||
Reference in New Issue
Block a user