Fetching: git on Mac OS (#24247)

Extend the changes in #24163 to unit tests.
This commit is contained in:
Peter Scheibel 2021-06-21 17:53:12 -07:00 committed by GitHub
parent 7b6ca59038
commit c83f4b01aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 6 deletions

View File

@ -766,6 +766,8 @@ class GitFetchStrategy(VCSFetchStrategy):
optional_attrs = ['tag', 'branch', 'commit', 'submodules', optional_attrs = ['tag', 'branch', 'commit', 'submodules',
'get_full_repo', 'submodules_delete'] 'get_full_repo', 'submodules_delete']
git_version_re = r'git version (\S+)'
def __init__(self, **kwargs): def __init__(self, **kwargs):
# Discards the keywords in kwargs that may conflict with the next call # Discards the keywords in kwargs that may conflict with the next call
# to __init__ # to __init__
@ -780,9 +782,16 @@ def __init__(self, **kwargs):
@property @property
def git_version(self): def git_version(self):
output = self.git('--version', output=str, error=str) return GitFetchStrategy.version_from_git(self.git)
match = re.search(r'git version (\S+)', output)
return Version(match.group(1)) if match else None @staticmethod
def version_from_git(git_exe):
"""Given a git executable, return the Version (this will fail if
the output cannot be parsed into a valid Version).
"""
version_output = git_exe('--version', output=str)
m = re.search(GitFetchStrategy.git_version_re, version_output)
return Version(m.group(1))
@property @property
def git(self): def git(self):

View File

@ -28,7 +28,7 @@ def check_git_version():
Refer: Refer:
https://github.com/git/git/commit/cc73385cf6c5c229458775bc92e7dbbe24d11611 https://github.com/git/git/commit/cc73385cf6c5c229458775bc92e7dbbe24d11611
""" """
git_version = ver(git('--version', output=str).lstrip('git version ')) git_version = spack.fetch_strategy.GitFetchStrategy.version_from_git(git)
return git_version >= ver(git_required_version) return git_version >= ver(git_required_version)

View File

@ -37,7 +37,8 @@ def git_version(request, monkeypatch):
use the backward-compatibility code paths with newer git versions. use the backward-compatibility code paths with newer git versions.
""" """
git = which('git', required=True) git = which('git', required=True)
real_git_version = ver(git('--version', output=str).lstrip('git version ')) real_git_version = (
spack.fetch_strategy.GitFetchStrategy.version_from_git(git))
if request.param is None: if request.param is None:
# Don't patch; run with the real git_version method. # Don't patch; run with the real git_version method.

View File

@ -259,7 +259,8 @@ class Git(AutotoolsPackage):
@classmethod @classmethod
def determine_version(cls, exe): def determine_version(cls, exe):
output = Executable(exe)('--version', output=str, error=str) output = Executable(exe)('--version', output=str, error=str)
match = re.search(r'git version (\S+)', output) match = re.search(
spack.fetch_strategy.GitFetchStrategy.git_version_re, output)
return match.group(1) if match else None return match.group(1) if match else None
@classmethod @classmethod