summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPeter Scheibel <scheibel1@llnl.gov>2021-06-21 17:53:12 -0700
committerGitHub <noreply@github.com>2021-06-21 17:53:12 -0700
commitc83f4b01aa621f936edff4bcb58cf5497e2eb516 (patch)
tree25cfd6e6be5c4d640bd54d1addbc75f6899d8e4e /lib
parent7b6ca5903861f7b7e648d651f5715ba6262e2a58 (diff)
downloadspack-c83f4b01aa621f936edff4bcb58cf5497e2eb516.tar.gz
spack-c83f4b01aa621f936edff4bcb58cf5497e2eb516.tar.bz2
spack-c83f4b01aa621f936edff4bcb58cf5497e2eb516.tar.xz
spack-c83f4b01aa621f936edff4bcb58cf5497e2eb516.zip
Fetching: git on Mac OS (#24247)
Extend the changes in #24163 to unit tests.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/fetch_strategy.py15
-rw-r--r--lib/spack/spack/test/cmd/is_git_repo.py2
-rw-r--r--lib/spack/spack/test/git_fetch.py3
3 files changed, 15 insertions, 5 deletions
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index da0b12556f..b4ca8b3e70 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -766,6 +766,8 @@ class GitFetchStrategy(VCSFetchStrategy):
optional_attrs = ['tag', 'branch', 'commit', 'submodules',
'get_full_repo', 'submodules_delete']
+ git_version_re = r'git version (\S+)'
+
def __init__(self, **kwargs):
# Discards the keywords in kwargs that may conflict with the next call
# to __init__
@@ -780,9 +782,16 @@ class GitFetchStrategy(VCSFetchStrategy):
@property
def git_version(self):
- output = self.git('--version', output=str, error=str)
- match = re.search(r'git version (\S+)', output)
- return Version(match.group(1)) if match else None
+ return GitFetchStrategy.version_from_git(self.git)
+
+ @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
def git(self):
diff --git a/lib/spack/spack/test/cmd/is_git_repo.py b/lib/spack/spack/test/cmd/is_git_repo.py
index 109f5030c7..fcfd1e010d 100644
--- a/lib/spack/spack/test/cmd/is_git_repo.py
+++ b/lib/spack/spack/test/cmd/is_git_repo.py
@@ -28,7 +28,7 @@ def check_git_version():
Refer:
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)
diff --git a/lib/spack/spack/test/git_fetch.py b/lib/spack/spack/test/git_fetch.py
index ad010e3ca5..e06077df83 100644
--- a/lib/spack/spack/test/git_fetch.py
+++ b/lib/spack/spack/test/git_fetch.py
@@ -37,7 +37,8 @@ def git_version(request, monkeypatch):
use the backward-compatibility code paths with newer git versions.
"""
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:
# Don't patch; run with the real git_version method.