Commit d0f854af authored by maruel@chromium.org's avatar maruel@chromium.org

Extract git version check code from gclient_scm.py into scm.py where it belongs.

Review URL: http://codereview.chromium.org/878001

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@41308 0039d316-1c4b-4281-b951-d872f2087c98
parent e0ff00dc
......@@ -555,21 +555,10 @@ class GitWrapper(SCMWrapper, scm.GIT):
print ""
def _CheckMinVersion(self, min_version):
def only_int(val):
if val.isdigit():
return int(val)
else:
return 0
version = self._Run(['--version'], cwd='.').split()[-1]
version_list = map(only_int, version.split('.'))
min_version_list = map(int, min_version.split('.'))
for min_ver in min_version_list:
ver = version_list.pop(0)
if min_ver > ver:
raise gclient_utils.Error('git version %s < minimum required %s' %
(version, min_version))
elif min_ver < ver:
return
(ok, current_version) = scm.GIT.AssertVersion(min_version)
if not ok:
raise gclient_utils.Error('git version %s < minimum required %s' %
(current_version, min_version))
def _GetCurrentBranch(self):
# Returns name of current branch
......
......@@ -270,6 +270,24 @@ class GIT(object):
root = GIT.Capture(['rev-parse', '--show-cdup'], path)[0].strip()
return os.path.abspath(os.path.join(path, root))
@staticmethod
def AssertVersion(min_version):
"""Asserts git's version is at least min_version."""
def only_int(val):
if val.isdigit():
return int(val)
else:
return 0
current_version = GIT.Capture(['--version'])[0].split()[-1]
current_version_list = map(only_int, current_version.split('.'))
for min_ver in map(int, min_version.split('.')):
ver = current_version_list.pop(0)
if ver < min_ver:
return (False, current_version)
elif ver > min_ver:
return (True, current_version)
return (True, current_version)
class SVN(object):
COMMAND = "svn"
......
......@@ -379,7 +379,8 @@ from :3
def testDir(self):
members = [
'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple',
'COMMAND', 'AssertVersion', 'Capture', 'CaptureStatus',
'FetchUpstreamTuple',
'FullUrlForRelativeUrl', 'GenerateDiff', 'GetBranch', 'GetBranchRef',
'GetCheckoutRoot', 'GetDifferentFiles', 'GetEmail', 'GetPatchName',
'GetSVNBranch', 'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput',
......
......@@ -118,7 +118,8 @@ from :3
def testMembersChanged(self):
self.mox.ReplayAll()
members = [
'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple',
'COMMAND', 'AssertVersion', 'Capture', 'CaptureStatus',
'FetchUpstreamTuple',
'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot',
'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch',
'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', 'ShortBranchName',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment