Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add git version to error output #2210

Merged
merged 1 commit into from Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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