Skip to content

Commit c05f58b

Browse files
committed
add git version to error output
1 parent 12b4823 commit c05f58b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

pre_commit/error_handler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pre_commit import output
1010
from pre_commit.errors import FatalError
1111
from pre_commit.store import Store
12+
from pre_commit.util import cmd_output_b
1213
from pre_commit.util import force_bytes
1314

1415

@@ -21,6 +22,9 @@ def _log_and_exit(
2122
error_msg = f'{msg}: {type(exc).__name__}: '.encode() + force_bytes(exc)
2223
output.write_line_b(error_msg)
2324

25+
_, git_version_b, _ = cmd_output_b('git', '--version', retcode=None)
26+
git_version = git_version_b.decode(errors='backslashreplace').rstrip()
27+
2428
storedir = Store().directory
2529
log_path = os.path.join(storedir, 'pre-commit.log')
2630
with contextlib.ExitStack() as ctx:
@@ -38,6 +42,7 @@ def _log_and_exit(
3842
_log_line()
3943
_log_line('```')
4044
_log_line(f'pre-commit version: {C.VERSION}')
45+
_log_line(f'git --version: {git_version}')
4146
_log_line('sys.version:')
4247
for line in sys.version.splitlines():
4348
_log_line(f' {line}')

tests/error_handler_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def test_log_and_exit(cap_out, mock_store_dir):
122122
r'\n'
123123
r'```\n'
124124
r'pre-commit version: \d+\.\d+\.\d+\n'
125+
r'git --version: git version .+\n'
125126
r'sys.version:\n'
126127
r'( .*\n)*'
127128
r'sys.executable: .*\n'

0 commit comments

Comments
 (0)