Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a009dd6

Browse files
authored
Merge pull request #982 from bnorquist/master
add helpful CI message
2 parents 03ac3b0 + 668e641 commit a009dd6

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

pre_commit/commands/run.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +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+
if args.all_files:
219+
output.write_line(
220+
'pre-commit hook(s) made changes.\n'
221+
'If you are seeing this message in CI, '
222+
'reproduce locally with: `pre-commit run --all-files`.\n'
223+
'To run `pre-commit` as part of git workflow, use '
224+
'`pre-commit install`.',
225+
)
218226
output.write_line('All changes made by hooks:')
219227
subprocess.call(('git', '--no-pager', 'diff', '--no-ext-diff'))
220228
return retval

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)