diff --git a/gclient_scm.py b/gclient_scm.py index a9984e857..1afd3f4ff 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -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 diff --git a/scm.py b/scm.py index 1dce4bd7c..b4553765a 100644 --- a/scm.py +++ b/scm.py @@ -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" diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 634ad9810..11033424b 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -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', diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index e5f8a64d8..5f3ff5ef3 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -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',