Skip to content

Commit 629fd87

Browse files
committed
Fix how version_info omits non-numeric fields
For #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".
1 parent ac20325 commit 629fd87

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

git/cmd.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
import contextlib
1010
import io
11+
import itertools
1112
import logging
1213
import os
1314
import signal
@@ -850,7 +851,8 @@ def version_info(self) -> Tuple[int, ...]:
850851
process_version = self._call_process("version")
851852
version_string = process_version.split(" ")[2]
852853
version_fields = version_string.split(".")[:4]
853-
self._version_info = tuple(int(n) for n in version_fields if n.isdigit())
854+
leading_numeric_fields = itertools.takewhile(str.isdigit, version_fields)
855+
self._version_info = tuple(map(int, leading_numeric_fields))
854856

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

0 commit comments

Comments
 (0)