3 ## repo default configuration
5 REPO_URL='https://chromium.googlesource.com/external/repo'
8 # Copyright (C) 2008 Google Inc.
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
14 # http://www.apache.org/licenses/LICENSE-2.0
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
22 # increment this whenever we make important changes to this script
25 # increment this if the MAINTAINER_KEYS block is modified
26 KEYRING_VERSION = (1, 4)
29 Repo Maintainer <repo@android.kernel.org>
30 -----BEGIN PGP PUBLIC KEY BLOCK-----
31 Version: GnuPG v1.4.2.2 (GNU/Linux)
33 mQGiBEj3ugERBACrLJh/ZPyVSKeClMuznFIrsQ+hpNnmJGw1a9GXKYKk8qHPhAZf
34 WKtrBqAVMNRLhL85oSlekRz98u41H5si5zcuv+IXJDF5MJYcB8f22wAy15lUqPWi
35 VCkk1l8qqLiuW0fo+ZkPY5qOgrvc0HW1SmdH649uNwqCbcKb6CxaTxzhOwCgj3AP
36 xI1WfzLqdJjsm1Nq98L0cLcD/iNsILCuw44PRds3J75YP0pze7YF/6WFMB6QSFGu
37 aUX1FsTTztKNXGms8i5b2l1B8JaLRWq/jOnZzyl1zrUJhkc0JgyZW5oNLGyWGhKD
38 Fxp5YpHuIuMImopWEMFIRQNrvlg+YVK8t3FpdI1RY0LYqha8pPzANhEYgSfoVzOb
39 fbfbA/4ioOrxy8ifSoga7ITyZMA+XbW8bx33WXutO9N7SPKS/AK2JpasSEVLZcON
40 ae5hvAEGVXKxVPDjJBmIc2cOe7kOKSi3OxLzBqrjS2rnjiP4o0ekhZIe4+ocwVOg
41 e0PLlH5avCqihGRhpoqDRsmpzSHzJIxtoeb+GgGEX8KkUsVAhbQpUmVwbyBNYWlu
42 dGFpbmVyIDxyZXBvQGFuZHJvaWQua2VybmVs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B2jZmhP6oXSe4K/LG5T
59 +WBRPDrHiGPhCzJRzm9BP0lTnGCAj3o9W90STZa65RK7IaYpC8TB35JTBEbrrNCp
60 w6lzd74LnNEp5eMlKDnXzUAgAH0yzCQeMl7t33QCdYx2hRs2wtTQSjGfAiNmj/WW
61 Vl5Jn+2jCDnRLenKHwVRFsBX2e0BiRWt/i9Y8fjorLCXVj4z+7yW6DawdLkJorEo
62 p3v5ILwfC7hVx4jHSnOgZ65L9s8EQdVr1ckN9243yta7rNgwfcqb60ILMFF1BRk/
63 0V7wCL+68UwwiQDvyMOQuqkysKLSDCLb7BFcyA7j6KG+5hpsREstFX2wK1yKeraz
64 5xGrFy8tfAaeBMIQ17gvFSp/suc9DYO0ICK2BISzq+F+ZiAKsjMYOBNdH/h0zobQ
65 HTHs37+/QLMomGEGKZMWi0dShU2J5mNRQu3Hhxl3hHDVbt5CeJBb26aQcQrFz69W
66 zE3GNvmJosh6leayjtI9P2A6iEkEGBECAAkFAkj3uiACGwwACgkQFlMNXpIPXGWp
67 TACbBS+Up3RpfYVfd63c1cDdlru13pQAn3NQy/SN858MkxN+zym86UBgOad2
69 -----END PGP PUBLIC KEY BLOCK-----
71 Conley Owens <cco3@android.com>
72 -----BEGIN PGP PUBLIC KEY BLOCK-----
73 Version: GnuPG v1.4.11 (GNU/Linux)
75 mQENBFHRvc8BCADFg45Xx/y6QDC+T7Y/gGc7vx0ww7qfOwIKlAZ9xG3qKunMxo+S
76 hPCnzEl3cq+6I1Ww/ndop/HB3N3toPXRCoN8Vs4/Hc7by+SnaLFnacrm+tV5/OgT
77 V37Lzt8lhay1Kl+YfpFwHYYpIEBLFV9knyfRXS/428W2qhdzYfvB15/AasRmwmor
78 py4NIzSs8UD/SPr1ihqNCdZM76+MQyN5HMYXW/ALZXUFG0pwluHFA7hrfPG74i8C
79 zMiP7qvMWIl/r/jtzHioH1dRKgbod+LZsrDJ8mBaqsZaDmNJMhss9g76XvfMyLra
80 9DI9/iFuBpGzeqBv0hwOG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+AjEO8at/VvgKr1AFvBRdZ7GkpI1o6DgPe7ZqX+1
97 dzQZt3e13W0rVBb/bUgx9iSLoeWP3aq/k+/GRGOR+S6F6BBSl0SQ2EF2+dIywb1x
98 JuinEP+AwLAUZ1Bsx9ISC0Agpk2VeHXPL3FGhroEmoMvBzO0kTFGyoeT7PR/BfKv
99 +H/g3HsL2LOB9uoIm8/5p2TTU5ttYCXMHhQZ81AY
101 -----END PGP PUBLIC KEY BLOCK-----
103 Stefan Zager <szager@chromium.org>
104 -----BEGIN PGP PUBLIC KEY BLOCK-----
105 Version: GnuPG v1.4.11 (GNU/Linux)
107 mQINBFIJOcgBEADwZIq4GRGoO1RJFKlrtVK501cwT5H+Acbizc9N5RxTkFmqxDjb
108 9ApUaPW6S1b8+nrzE9P1Ri5erfzipuStfaZ/Wl3mP1JjKulibddmgnPOEbAJ673k
109 Vj85RUO4rt2oZAHnZN3D3gFJzVY8JVlZ47Enj9fTqzcW78FVsPCpIT9P2LpTLWeE
110 jX9Cjxeimy6VvyJstIcDLYhlpUN5UWen79L4LFAkHf3luLuU4W3p9NriqUsy5UG2
111 8vO6QdhKrCr5wsjDFFeVnpMtjlSeZJAWH+XhFFibMX1xP5R9BTuJfzw3kOVKvcE0
112 e9ClxgoulepXPv2xnDkqO3pG2gQVzl8LA+Aol8/IXfa7KP5FBkxK/g1cDuDtXRk4
113 YLpLaLYeeKEhhOHLpsKYkK2DXTIcN+56UnTLGolummpZnCM8UUSZxQgbkFgk4YJL
114 Elip0hgLZzqEl5h9vjmnQp89AZIHKcgNmzn+szLTOR9x24joaLyQ534x8OSC8lmu
115 tJv2tQjDOVGWVwvY4gOTpyxCWMwur6WOiMk/TPWdiVRFWAGrAHwf0/CTBEqNhosh
116 sVXfPeMADBA0PorDbJ6kwcOkLUTGf8CT7OG1R9TuKPEmSjK7BYu/pT4DXitaRCiv
117 uPVlwbVFpLFr0/jwaKJVMLUjL5MaYwzjJqI2c4RdROZhpMhkn4LvCMmFSQARAQAB
118 tCJTdGVmYW4gWmFnZXIgPHN6YWdlckBjaHJvbWl1bS5vcmc+iQI4BBMBAgAiBQJS
119 CTnIAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRDcuoHPGCdZNU0UD/9y
120 0zwwOJH2UGPAzZ0YVzr7p0HtKedoxuFvPkdQxlBIaUOueMzFRmNQu3GI9irAu3MQ
121 Jkip8/gi7dnLVmJyS/zWARBaRGwSVd1++87XDjw8n7l181p7394X0Agq/heri599
122 YheHXkxXKVMPqByWNEPHu4eDbxeJTaDIjcKC2pzKQkm6HbWgW4wA9gCh1TRki8FP
123 LMv1Fu/dr13STCR9P2evsTRZ+ZSJhTSboHNHeEAJGiGZQAsN94oht7647lYj+AyR
124 ThzyHDMXXiDr8jPJIkyRilY+y82bCOatOfPoCkce3VI+LRUGJ19hJY01m4RRneIE
125 55l7fXR3zggcsONjV5b+oLcGQPGgX9w64BJ7khT7Wb9+kuyrdJBIBzJsaACFEbri
126 pPi02FS/HahYpLC3J66REAeNyofgVXau6WQsHrHMGsBTL9aAr0nrCrkF4Nyyc2Jd
127 do6nYuljuUhORqbEECmmBM2eBtkL6Ac92D6WMBIwBOC5tCNHO2YFIvi8Y8EuE8sc
128 1zB5U5Ai4SIu2icRAhzAhCRaUq02cMWuELKH6Vuh9nzgEefFWty6vPbKEyZLu19D
129 B80aqP1cTN88FjtKQ/eTF29TUB6AefUeBS17e2e3WUMy4nc8tduuOFYfiHP40ScP
130 wOoatwfzpiTIPGbocUEPL+pS0O/Xy8SINxFMCud3zA==
132 -----END PGP PUBLIC KEY BLOCK-----
134 David James <davidjames@google.com>
135 -----BEGIN PGP PUBLIC KEY BLOCK-----
138 mQINBFQKWWsBEACjAxD8xLqNVFX/qOAKFW7R63J3KkkXQKyH5KmSWZnmdfTg4AeR
139 h9sAUls16nHiOFp/MRLFFhax8dm33zfED+zHpISFUkMq2Q3UyP6Z6eSpJyYriEF1
140 hP7PpwksEnh+hoQ36fhsY1vaQRgTCO8X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173 GwwACgkQSlDprdejN6wHURAAncjYkIkSseO8lldTVu0qJi2vetc2Q6bR8Lw1hTAT
174 TB2LcbFheTu6Q/sxDSC5slovFSgyDp8wNkDf88+fxV38LC00IeWz7a9EGPzLzA+D
175 fNFdctnxXZGaYB3cQ17TkKFj4AMqbzKPkt4xYWU/WdSWPPd4feFJVjg7l8BIxafF
176 58ZYbWN3DwAgKE9DDZ9praTNC/2ytWh21a2j8LR4GlYERW1pMGrMt37IGvZqbU6W
177 a7HWaB7f0eXg5M5GTr7KP6TTGwY/500cI4fDme6bih/jXDS4vV53b1HHgvzQFXw/
178 XURueobmqsbQQzDGsqPzkYJM4fxXu0TWNhW8CieZMMypPq3uSgvN3jTu2JB9NAEz
179 21Pso0NzKm6wxhMzPA6KWILmR2KQn/t51NTE6u0+8e9RmQeg9Ce+IpPzPLsGuNca
180 u+r4LcB98D8jIUXz9PPbIHiDLJjMWOG8olZz1zcHpt86b+bf8c9TxFAE8p3G/jpQ
181 qanHjtbgNmkz+JpvJ9CTEEo69tkcbmOaCNwCWQL+Doqqi7tWMYUbAw0Rk+lOSu/N
182 4cAccd41XU/GmIs9zKkbORWubhfFndc7AXnPUU2otjqMQq0f+QCQrHPdyARf2QCm
183 j8zzwdwkRpt3SSvqzh3+L3Zq8xeb2M6u/QLz4aLFTR7yQJed0DJFUcISii9ccJr/
186 -----END PGP PUBLIC KEY BLOCK-----
189 GIT = 'git' # our git command
190 MIN_GIT_VERSION = (1, 7, 2) # minimum supported git version
191 repodir = '.repo' # name of repo's private directory
192 S_repo = 'repo' # special repo repository
193 S_manifests = 'manifests' # special manifest repository
194 REPO_MAIN = S_repo + '/main.py' # main script
195 MIN_PYTHON_VERSION = (2, 6) # minimum supported python version
206 if sys.version_info[0] == 3:
207 import urllib.request
212 urllib = imp.new_module('urllib')
213 urllib.request = urllib2
214 urllib.error = urllib2
217 def _print(*objects, **kwargs):
218 sep = kwargs.get('sep', ' ')
219 end = kwargs.get('end', '\n')
220 out = kwargs.get('file', sys.stdout)
221 out.write(sep.join(objects) + end)
224 # Python version check
225 ver = sys.version_info
227 _print('warning: Python 3 support is currently experimental. YMMV.\n'
228 'Please use Python 2.6 - 2.7 instead.',
230 if (ver[0], ver[1]) < MIN_PYTHON_VERSION:
231 _print('error: Python version %s unsupported.\n'
232 'Please use Python 2.6 - 2.7 instead.'
233 % sys.version.split(' ')[0], file=sys.stderr)
236 home_dot_repo = os.path.expanduser('~/.repoconfig')
237 gpg_dir = os.path.join(home_dot_repo, 'gnupg')
240 init_optparse = optparse.OptionParser(usage="repo init -u url [options]")
243 group = init_optparse.add_option_group('Logging options')
244 group.add_option('-q', '--quiet',
245 dest="quiet", action="store_true", default=False,
249 group = init_optparse.add_option_group('Manifest options')
250 group.add_option('-u', '--manifest-url',
252 help='manifest repository location', metavar='URL')
253 group.add_option('-b', '--manifest-branch',
254 dest='manifest_branch',
255 help='manifest branch or revision', metavar='REVISION')
256 group.add_option('-m', '--manifest-name',
257 dest='manifest_name',
258 help='initial manifest file', metavar='NAME.xml')
259 group.add_option('--mirror',
260 dest='mirror', action='store_true',
261 help='create a replica of the remote repositories '
262 'rather than a client working directory')
263 group.add_option('--reference',
265 help='location of mirror directory', metavar='DIR')
266 group.add_option('--depth', type='int', default=None,
268 help='create a shallow clone with given depth; see git clone')
269 group.add_option('--archive',
270 dest='archive', action='store_true',
271 help='checkout an archive instead of a git repository for '
272 'each project. See git archive.')
273 group.add_option('-g', '--groups',
274 dest='groups', default='default',
275 help='restrict manifest projects to ones with specified '
276 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]',
278 group.add_option('-p', '--platform',
279 dest='platform', default="auto",
280 help='restrict manifest projects to ones with a specified '
281 'platform group [auto|all|none|linux|darwin|...]',
286 group = init_optparse.add_option_group('repo Version options')
287 group.add_option('--repo-url',
289 help='repo repository location', metavar='URL')
290 group.add_option('--repo-branch',
292 help='repo branch or revision', metavar='REVISION')
293 group.add_option('--no-repo-verify',
294 dest='no_repo_verify', action='store_true',
295 help='do not verify repo source code')
298 group = init_optparse.add_option_group('Other options')
299 group.add_option('--config-name',
300 dest='config_name', action="store_true", default=False,
301 help='Always prompt for name/e-mail')
303 class CloneFailure(Exception):
304 """Indicate the remote clone of repo itself failed.
309 """Installs repo by cloning it over the network.
311 opt, args = init_optparse.parse_args(args)
313 init_optparse.print_usage()
319 extra_args.append('--repo-url=%s' % url)
321 branch = opt.repo_branch
324 extra_args.append('--repo-branch=%s' % branch)
326 if branch.startswith('refs/heads/'):
327 branch = branch[len('refs/heads/'):]
328 if branch.startswith('refs/'):
329 _print("fatal: invalid branch name '%s'" % branch, file=sys.stderr)
335 if e.errno != errno.EEXIST:
336 _print('fatal: cannot make %s directory: %s'
337 % (repodir, e.strerror), file=sys.stderr)
338 # Don't raise CloneFailure; that would delete the
339 # name. Instead exit immediately.
346 can_verify = SetupGnuPG(opt.quiet)
350 dst = os.path.abspath(os.path.join(repodir, S_repo))
351 _Clone(url, dst, opt.quiet)
353 if can_verify and not opt.no_repo_verify:
354 rev = _Verify(dst, branch, opt.quiet)
356 rev = 'refs/remotes/origin/%s^0' % branch
358 _Checkout(dst, branch, rev, opt.quiet)
361 _print('fatal: repo init failed; run without --quiet to see why',
366 def ParseGitVersion(ver_str):
367 if not ver_str.startswith('git version '):
370 num_ver_str = ver_str[len('git version '):].strip().split('-')[0]
372 for num_str in num_ver_str.split('.')[:3]:
373 if num_str.isdigit():
374 to_tuple.append(int(num_str))
377 return tuple(to_tuple)
380 def _CheckGitVersion():
381 cmd = [GIT, '--version']
383 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
385 _print(file=sys.stderr)
386 _print("fatal: '%s' is not available" % GIT, file=sys.stderr)
387 _print('fatal: %s' % e, file=sys.stderr)
388 _print(file=sys.stderr)
389 _print('Please make sure %s is installed and in your path.' % GIT,
393 ver_str = proc.stdout.read().strip()
397 ver_act = ParseGitVersion(ver_str)
399 _print('error: "%s" unsupported' % ver_str, file=sys.stderr)
402 if ver_act < MIN_GIT_VERSION:
403 need = '.'.join(map(str, MIN_GIT_VERSION))
404 _print('fatal: git %s or later required' % need, file=sys.stderr)
408 def NeedSetupGnuPG():
409 if not os.path.isdir(home_dot_repo):
412 kv = os.path.join(home_dot_repo, 'keyring-version')
413 if not os.path.exists(kv):
420 kv = tuple(map(int, kv.split('.')))
421 if kv < KEYRING_VERSION:
426 def SetupGnuPG(quiet):
428 os.mkdir(home_dot_repo)
430 if e.errno != errno.EEXIST:
431 _print('fatal: cannot make %s directory: %s'
432 % (home_dot_repo, e.strerror), file=sys.stderr)
436 os.mkdir(gpg_dir, stat.S_IRWXU)
438 if e.errno != errno.EEXIST:
439 _print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror),
443 env = os.environ.copy()
444 env['GNUPGHOME'] = gpg_dir.encode()
446 cmd = ['gpg', '--import']
448 proc = subprocess.Popen(cmd,
450 stdin = subprocess.PIPE)
453 _print('warning: gpg (GnuPG) is not available.', file=sys.stderr)
454 _print('warning: Installing it is strongly encouraged.', file=sys.stderr)
455 _print(file=sys.stderr)
458 proc.stdin.write(MAINTAINER_KEYS)
462 _print('fatal: registering repo maintainer keys failed', file=sys.stderr)
466 fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w')
467 fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n')
472 def _SetConfig(local, name, value):
473 """Set a git configuration option to the specified value.
475 cmd = [GIT, 'config', name, value]
476 if subprocess.Popen(cmd, cwd = local).wait() != 0:
483 mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
489 mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
490 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
493 handlers.append(urllib.request.HTTPBasicAuthHandler(mgr))
494 handlers.append(urllib.request.HTTPDigestAuthHandler(mgr))
496 if 'http_proxy' in os.environ:
497 url = os.environ['http_proxy']
498 handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
499 if 'REPO_CURL_VERBOSE' in os.environ:
500 handlers.append(urllib.request.HTTPHandler(debuglevel=1))
501 handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
502 urllib.request.install_opener(urllib.request.build_opener(*handlers))
504 def _Fetch(url, local, src, quiet):
506 _print('Get %s' % url, file=sys.stderr)
510 cmd.append('--quiet')
511 err = subprocess.PIPE
515 cmd.append('+refs/heads/*:refs/remotes/origin/*')
516 cmd.append('refs/tags/*:refs/tags/*')
518 proc = subprocess.Popen(cmd, cwd = local, stderr = err)
525 def _DownloadBundle(url, local, quiet):
526 if not url.endswith('/'):
528 url += 'clone.bundle'
530 proc = subprocess.Popen(
531 [GIT, 'config', '--get-regexp', 'url.*.insteadof'],
533 stdout = subprocess.PIPE)
534 for line in proc.stdout:
535 m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line)
539 if url.startswith(old_url):
540 url = new_url + url[len(old_url):]
545 if not url.startswith('http:') and not url.startswith('https:'):
548 dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b')
551 r = urllib.request.urlopen(url)
552 except urllib.error.HTTPError as e:
553 if e.code in [403, 404]:
555 _print('fatal: Cannot get %s' % url, file=sys.stderr)
556 _print('fatal: HTTP error %s' % e.code, file=sys.stderr)
558 except urllib.error.URLError as e:
559 _print('fatal: Cannot get %s' % url, file=sys.stderr)
560 _print('fatal: error %s' % e.reason, file=sys.stderr)
564 _print('Get %s' % url, file=sys.stderr)
575 def _ImportBundle(local):
576 path = os.path.join(local, '.git', 'clone.bundle')
578 _Fetch(local, local, path, True)
582 def _Clone(url, local, quiet):
583 """Clones a git repository to a new subdirectory of repodir
588 _print('fatal: cannot make %s directory: %s' % (local, e.strerror),
592 cmd = [GIT, 'init', '--quiet']
594 proc = subprocess.Popen(cmd, cwd = local)
596 _print(file=sys.stderr)
597 _print("fatal: '%s' is not available" % GIT, file=sys.stderr)
598 _print('fatal: %s' % e, file=sys.stderr)
599 _print(file=sys.stderr)
600 _print('Please make sure %s is installed and in your path.' % GIT,
604 _print('fatal: could not create %s' % local, file=sys.stderr)
608 _SetConfig(local, 'remote.origin.url', url)
609 _SetConfig(local, 'remote.origin.fetch',
610 '+refs/heads/*:refs/remotes/origin/*')
611 if _DownloadBundle(url, local, quiet):
614 _Fetch(url, local, 'origin', quiet)
617 def _Verify(cwd, branch, quiet):
618 """Verify the branch has been signed by a tag.
620 cmd = [GIT, 'describe', 'origin/%s' % branch]
621 proc = subprocess.Popen(cmd,
622 stdout=subprocess.PIPE,
623 stderr=subprocess.PIPE,
625 cur = proc.stdout.read().strip()
631 if proc.wait() != 0 or not cur:
632 _print(file=sys.stderr)
633 _print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr)
636 m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
640 _print(file=sys.stderr)
641 _print("info: Ignoring branch '%s'; using tagged release '%s'"
642 % (branch, cur), file=sys.stderr)
643 _print(file=sys.stderr)
645 env = os.environ.copy()
646 env['GNUPGHOME'] = gpg_dir.encode()
648 cmd = [GIT, 'tag', '-v', cur]
649 proc = subprocess.Popen(cmd,
650 stdout = subprocess.PIPE,
651 stderr = subprocess.PIPE,
654 out = proc.stdout.read()
657 err = proc.stderr.read()
661 _print(file=sys.stderr)
662 _print(out, file=sys.stderr)
663 _print(err, file=sys.stderr)
664 _print(file=sys.stderr)
669 def _Checkout(cwd, branch, rev, quiet):
670 """Checkout an upstream branch into the repository and track it.
672 cmd = [GIT, 'update-ref', 'refs/heads/default', rev]
673 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
676 _SetConfig(cwd, 'branch.default.remote', 'origin')
677 _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch)
679 cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default']
680 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
683 cmd = [GIT, 'read-tree', '--reset', '-u']
687 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
692 """Look for a repo installation, starting at the current directory.
698 while curdir != '/' \
699 and curdir != olddir \
701 repo = os.path.join(curdir, repodir, REPO_MAIN)
702 if not os.path.isfile(repo):
705 curdir = os.path.dirname(curdir)
706 return (repo, os.path.join(curdir, repodir))
713 def _ParseArguments(args):
718 for i in range(len(args)):
720 if a == '-h' or a == '--help':
723 elif not a.startswith('-'):
732 """usage: repo COMMAND [ARGS]
734 repo is not yet installed. Use "repo init" to install it here.
736 The most commonly used repo commands are:
738 init Install repo in the current working directory
739 help Display detailed help on a command
741 For access to the full online help, install repo ("repo init").
742 """, file=sys.stderr)
748 if args[0] == 'init':
749 init_optparse.print_help()
752 _print("error: '%s' is not a bootstrap command.\n"
753 ' For access to online help, install repo ("repo init").'
754 % args[0], file=sys.stderr)
761 _print('error: repo is not installed. Use "repo init" to install it here.',
766 def _NoCommands(cmd):
767 _print("""error: command '%s' requires repo to be installed first.
768 Use "repo init" to install it here.""" % cmd, file=sys.stderr)
772 def _RunSelf(wrapper_path):
773 my_dir = os.path.dirname(wrapper_path)
774 my_main = os.path.join(my_dir, 'main.py')
775 my_git = os.path.join(my_dir, '.git')
777 if os.path.isfile(my_main) and os.path.isdir(my_git):
778 for name in ['git_config.py',
781 if not os.path.exists(os.path.join(my_dir, name)):
783 return my_main, my_git
787 def _SetDefaultsTo(gitdir):
792 proc = subprocess.Popen([GIT,
793 '--git-dir=%s' % gitdir,
796 stdout = subprocess.PIPE,
797 stderr = subprocess.PIPE)
798 REPO_REV = proc.stdout.read().strip()
805 _print('fatal: %s has no current branch' % gitdir, file=sys.stderr)
810 repo_main, rel_repo_dir = _FindRepo()
811 cmd, opt, args = _ParseArguments(orig_args)
813 wrapper_path = os.path.abspath(__file__)
814 my_main, my_git = _RunSelf(wrapper_path)
825 _SetDefaultsTo(my_git)
829 for root, dirs, files in os.walk(repodir, topdown=False):
831 os.remove(os.path.join(root, name))
833 os.rmdir(os.path.join(root, name))
836 repo_main, rel_repo_dir = _FindRepo()
840 if cmd == 'sync' and NeedSetupGnuPG():
846 ver_str = '.'.join(map(str, VERSION))
847 me = [sys.executable, repo_main,
848 '--repo-dir=%s' % rel_repo_dir,
849 '--wrapper-version=%s' % ver_str,
850 '--wrapper-path=%s' % wrapper_path,
853 me.extend(extra_args)
855 os.execv(sys.executable, me)
857 _print("fatal: unable to start %s" % repo_main, file=sys.stderr)
858 _print("fatal: %s" % e, file=sys.stderr)
862 if __name__ == '__main__':