There was an error while loading. Please reload this page.
1 parent 6663009 commit daa67ffCopy full SHA for daa67ff
2 files changed
pre_commit/commands/run.py
@@ -166,16 +166,17 @@ def _run_single_hook(
166
files_modified = False
167
out = b''
168
elif not filenames and not hook.always_run:
169
- output.write(
170
- _full_msg(
171
- start=hook.name,
172
- postfix=NO_FILES,
173
- end_msg=SKIPPED,
174
- end_color=color.TURQUOISE,
175
- use_color=use_color,
176
- cols=cols,
177
- ),
178
- )
+ if verbose:
+ output.write(
+ _full_msg(
+ start=hook.name,
+ postfix=NO_FILES,
+ end_msg=SKIPPED,
+ end_color=color.TURQUOISE,
+ use_color=use_color,
+ cols=cols,
+ ),
179
+ )
180
duration = None
181
retcode = 0
182
diff_after = diff_before
@@ -205,14 +206,18 @@ def _run_single_hook(
205
206
# if the hook makes changes, fail the commit
207
files_modified = diff_before != diff_after
208
- if retcode or files_modified:
209
+ failed = retcode or files_modified
210
+ if failed:
211
print_color = color.RED
212
status = 'Failed'
213
else:
214
print_color = color.GREEN
215
status = 'Passed'
216
- output.write_line(color.format_color(status, print_color, use_color))
217
+ if failed or verbose or not output.try_clear_line():
218
+ output.write_line(
219
+ color.format_color(status, print_color, use_color),
220
221
222
if verbose or hook.verbose or retcode or files_modified:
223
_subtle_line(f'- hook id: {hook.id}', use_color)
pre_commit/output.py
@@ -31,3 +31,12 @@ def write_line_b(
31
32
def write_line(s: str | None = None, **kwargs: Any) -> None:
33
write_line_b(s.encode() if s is not None else s, **kwargs)
34
+
35
36
+def try_clear_line() -> bool:
37
+ if sys.stdout.isatty():
38
+ sys.stdout.buffer.write(b'\r')
39
+ sys.stdout.buffer.flush()
40
+ return True
41
+ else:
42
+ return False
0 commit comments