Skip to content

Commit

Permalink
Fetching: git on Mac OS (spack#24247)
Browse files Browse the repository at this point in the history
Extend the changes in spack#24163 to unit tests.
  • Loading branch information
scheibelp authored Jun 22, 2021
1 parent 7b6ca59 commit c83f4b0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
15 changes: 12 additions & 3 deletions lib/spack/spack/fetch_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -780,9 +782,16 @@ def __init__(self, **kwargs):

@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):
Expand Down
2 changes: 1 addition & 1 deletion lib/spack/spack/test/cmd/is_git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
3 changes: 2 additions & 1 deletion lib/spack/spack/test/git_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion var/spack/repos/builtin/packages/git/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ class Git(AutotoolsPackage):
@classmethod
def determine_version(cls, exe):
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

@classmethod
Expand Down

0 comments on commit c83f4b0

Please sign in to comment.