summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--git_command.py24
-rw-r--r--subcmds/init.py17
2 files changed, 26 insertions, 15 deletions
diff --git a/git_command.py b/git_command.py
index 7ff1abac..d56ad0a8 100644
--- a/git_command.py
+++ b/git_command.py
@@ -68,6 +68,30 @@ class _GitCall(object):
68 return fun 68 return fun
69git = _GitCall() 69git = _GitCall()
70 70
71_git_version = None
72
73def git_require(min_version, fail=False):
74 global _git_version
75
76 if _git_version is None:
77 ver_str = git.version()
78 if ver_str.startswith('git version '):
79 _git_version = tuple(
80 map(lambda x: int(x),
81 ver_str[len('git version '):].strip().split('.')[0:3]
82 ))
83 else:
84 print >>sys.stderr, 'fatal: "%s" unsupported' % ver_str
85 sys.exit(1)
86
87 if min_version <= _git_version:
88 return True
89 if fail:
90 need = '.'.join(map(lambda x: str(x), min_version))
91 print >>sys.stderr, 'fatal: git %s or later required' % need
92 sys.exit(1)
93 return False
94
71class GitCommand(object): 95class GitCommand(object):
72 def __init__(self, 96 def __init__(self,
73 project, 97 project,
diff --git a/subcmds/init.py b/subcmds/init.py
index 5ba4d794..fbc406e2 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -20,7 +20,7 @@ from color import Coloring
20from command import InteractiveCommand, MirrorSafeCommand 20from command import InteractiveCommand, MirrorSafeCommand
21from error import ManifestParseError 21from error import ManifestParseError
22from project import SyncBuffer 22from project import SyncBuffer
23from git_command import git, MIN_GIT_VERSION 23from git_command import git_require, MIN_GIT_VERSION
24 24
25class Init(InteractiveCommand, MirrorSafeCommand): 25class Init(InteractiveCommand, MirrorSafeCommand):
26 common = True 26 common = True
@@ -85,19 +85,6 @@ to update the working directory files.
85 dest='no_repo_verify', action='store_true', 85 dest='no_repo_verify', action='store_true',
86 help='do not verify repo source code') 86 help='do not verify repo source code')
87 87
88 def _CheckGitVersion(self):
89 ver_str = git.version()
90 if not ver_str.startswith('git version '):
91 print >>sys.stderr, 'error: "%s" unsupported' % ver_str
92 sys.exit(1)
93
94 ver_str = ver_str[len('git version '):].strip()
95 ver_act = tuple(map(lambda x: int(x), ver_str.split('.')[0:3]))
96 if ver_act < MIN_GIT_VERSION:
97 need = '.'.join(map(lambda x: str(x), MIN_GIT_VERSION))
98 print >>sys.stderr, 'fatal: git %s or later required' % need
99 sys.exit(1)
100
101 def _SyncManifest(self, opt): 88 def _SyncManifest(self, opt):
102 m = self.manifest.manifestProject 89 m = self.manifest.manifestProject
103 is_new = not m.Exists 90 is_new = not m.Exists
@@ -214,7 +201,7 @@ to update the working directory files.
214 gc.SetString('color.ui', 'auto') 201 gc.SetString('color.ui', 'auto')
215 202
216 def Execute(self, opt, args): 203 def Execute(self, opt, args):
217 self._CheckGitVersion() 204 git_require(MIN_GIT_VERSION, fail=True)
218 self._SyncManifest(opt) 205 self._SyncManifest(opt)
219 self._LinkManifest(opt.manifest_name) 206 self._LinkManifest(opt.manifest_name)
220 207