|
6 | 6 | import urllib.request
|
7 | 7 | from typing import List, Optional, Tuple
|
8 | 8 |
|
9 |
| -from pip._vendor.packaging.version import _BaseVersion |
10 |
| -from pip._vendor.packaging.version import parse as parse_version |
11 |
| - |
12 | 9 | from pip._internal.exceptions import BadCommand, InstallationError
|
13 | 10 | from pip._internal.utils.misc import HiddenText, display_path, hide_url
|
14 | 11 | from pip._internal.utils.subprocess import make_command
|
|
29 | 26 | logger = logging.getLogger(__name__)
|
30 | 27 |
|
31 | 28 |
|
| 29 | +GIT_VERSION_REGEX = re.compile( |
| 30 | + r"^git version " # Prefix. |
| 31 | + r"(\d+)" # Major. |
| 32 | + r"\.(\d+)" # Dot, minor. |
| 33 | + r"(?:\.(\d+))?" # Optional dot, patch. |
| 34 | + r".*$" # Suffix, including any pre- and post-release segments we don't care about. |
| 35 | +) |
| 36 | + |
32 | 37 | HASH_REGEX = re.compile('^[a-fA-F0-9]{40}$')
|
33 | 38 |
|
34 | 39 | # SCP (Secure copy protocol) shorthand. e.g. '[email protected]:foo/bar.git'
|
@@ -83,21 +88,14 @@ def is_immutable_rev_checkout(self, url, dest):
|
83 | 88 | )
|
84 | 89 | return not is_tag_or_branch
|
85 | 90 |
|
86 |
| - def get_git_version(self): |
87 |
| - # type: () -> _BaseVersion |
88 |
| - VERSION_PFX = 'git version ' |
| 91 | + def get_git_version(self) -> Tuple[int, ...]: |
89 | 92 | version = self.run_command(
|
90 | 93 | ['version'], show_stdout=False, stdout_only=True
|
91 | 94 | )
|
92 |
| - if version.startswith(VERSION_PFX): |
93 |
| - version = version[len(VERSION_PFX):].split()[0] |
94 |
| - else: |
95 |
| - version = '' |
96 |
| - # get first 3 positions of the git version because |
97 |
| - # on windows it is x.y.z.windows.t, and this parses as |
98 |
| - # LegacyVersion which always smaller than a Version. |
99 |
| - version = '.'.join(version.split('.')[:3]) |
100 |
| - return parse_version(version) |
| 95 | + match = GIT_VERSION_REGEX.match(version) |
| 96 | + if not match: |
| 97 | + return () |
| 98 | + return tuple(int(c) for c in match.groups()) |
101 | 99 |
|
102 | 100 | @classmethod
|
103 | 101 | def get_current_branch(cls, location):
|
@@ -301,7 +299,7 @@ def switch(self, dest, url, rev_options):
|
301 | 299 | def update(self, dest, url, rev_options):
|
302 | 300 | # type: (str, HiddenText, RevOptions) -> None
|
303 | 301 | # First fetch changes from the default remote
|
304 |
| - if self.get_git_version() >= parse_version('1.9.0'): |
| 302 | + if self.get_git_version() >= (1, 9): |
305 | 303 | # fetch tags in addition to everything else
|
306 | 304 | self.run_command(['fetch', '-q', '--tags'], cwd=dest)
|
307 | 305 | else:
|
|
0 commit comments