Skip to content

Commit

Permalink
Merge pull request #2210 from pre-commit/git-version
Browse files Browse the repository at this point in the history
add git version to error output
  • Loading branch information
asottile committed Jan 16, 2022
2 parents 12b4823 + c05f58b commit 7a305e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pre_commit/error_handler.py
Expand Up @@ -9,6 +9,7 @@
from pre_commit import output
from pre_commit.errors import FatalError
from pre_commit.store import Store
from pre_commit.util import cmd_output_b
from pre_commit.util import force_bytes


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

_, git_version_b, _ = cmd_output_b('git', '--version', retcode=None)
git_version = git_version_b.decode(errors='backslashreplace').rstrip()

storedir = Store().directory
log_path = os.path.join(storedir, 'pre-commit.log')
with contextlib.ExitStack() as ctx:
Expand All @@ -38,6 +42,7 @@ def _log_and_exit(
_log_line()
_log_line('```')
_log_line(f'pre-commit version: {C.VERSION}')
_log_line(f'git --version: {git_version}')
_log_line('sys.version:')
for line in sys.version.splitlines():
_log_line(f' {line}')
Expand Down
1 change: 1 addition & 0 deletions tests/error_handler_test.py
Expand Up @@ -122,6 +122,7 @@ def test_log_and_exit(cap_out, mock_store_dir):
r'\n'
r'```\n'
r'pre-commit version: \d+\.\d+\.\d+\n'
r'git --version: git version .+\n'
r'sys.version:\n'
r'( .*\n)*'
r'sys.executable: .*\n'
Expand Down

0 comments on commit 7a305e5

Please sign in to comment.