Skip to content

Commit 71a740d

Browse files
bnorquistasottile
authored andcommitted
add helpful message and test
1 parent 03ac3b0 commit 71a740d

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

pre_commit/commands/run.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,14 @@ def _run_hooks(config, hooks, args, environ):
215215
if retval and config['fail_fast']:
216216
break
217217
if retval and args.show_diff_on_failure and git.has_diff():
218-
output.write_line('All changes made by hooks:')
218+
if args.all_files:
219+
output.write_line(
220+
'Pre-commit hook(s) made changes. '
221+
'If you are seeing this message on CI,'
222+
' reproduce locally with: pre-commit run --all-files',
223+
)
224+
else:
225+
output.write_line('All changes made by hooks:')
219226
subprocess.call(('git', '--no-pager', 'diff', '--no-ext-diff'))
220227
return retval
221228

tests/commands/run_test.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,41 @@ def test_global_exclude(cap_out, store, tempdir_factory):
178178
assert printed.endswith(expected)
179179

180180

181-
def test_show_diff_on_failure(capfd, cap_out, store, tempdir_factory):
181+
@pytest.mark.parametrize(
182+
('args', 'expected_out'),
183+
[
184+
(
185+
{
186+
'show_diff_on_failure': True,
187+
},
188+
b'All changes made by hooks:',
189+
),
190+
(
191+
{
192+
'show_diff_on_failure': True,
193+
'all_files': True,
194+
},
195+
b'reproduce locally with: pre-commit run --all-files',
196+
),
197+
],
198+
)
199+
def test_show_diff_on_failure(
200+
args,
201+
expected_out,
202+
capfd,
203+
cap_out,
204+
store,
205+
tempdir_factory,
206+
):
182207
git_path = make_consuming_repo(
183208
tempdir_factory, 'modified_file_returns_zero_repo',
184209
)
185210
with cwd(git_path):
186211
stage_a_file('bar.py')
187212
_test_run(
188-
cap_out, store, git_path, {'show_diff_on_failure': True},
213+
cap_out, store, git_path, args,
189214
# we're only testing the output after running
190-
(), 1, True,
215+
expected_out, 1, True,
191216
)
192217
out, _ = capfd.readouterr()
193218
assert 'diff --git' in out

0 commit comments

Comments
 (0)