Skip to content

Commit

Permalink
Fix how version_info omits non-numeric fields
Browse files Browse the repository at this point in the history
For gitpython-developers#1833.

This makes version_info parsing stop including fields after the
first non-numeric field, rather than skipping non-numeric fields
and including subsequent numeric fields that then wrongly appear to
have the original position and significance of the dropped field.

This actually stops at (rather than merely after) a non-numeric
field, i.e., potentially parseable fields that are not fully
numeric, such as "2a", are stopped at, rather than parsed as "2".
  • Loading branch information
EliahKagan committed Feb 22, 2024
1 parent ac20325 commit 629fd87
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import contextlib
import io
import itertools
import logging
import os
import signal
Expand Down Expand Up @@ -850,7 +851,8 @@ def version_info(self) -> Tuple[int, ...]:
process_version = self._call_process("version")
version_string = process_version.split(" ")[2]
version_fields = version_string.split(".")[:4]
self._version_info = tuple(int(n) for n in version_fields if n.isdigit())
leading_numeric_fields = itertools.takewhile(str.isdigit, version_fields)
self._version_info = tuple(map(int, leading_numeric_fields))

# This value will be considered valid until the next refresh.
self._version_info_token = refresh_token
Expand Down

0 comments on commit 629fd87

Please sign in to comment.