blob: 01c1cb0eec1578f840244379abce50f2cdac917b [file] [log] [blame]
David Pursehouse8898e2f2012-11-14 07:51:03 +09001#!/usr/bin/env python
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07002
3## repo default configuration
4##
David Pursehouse8f62fb72012-11-14 12:09:38 +09005REPO_URL = 'https://gerrit.googlesource.com/git-repo'
6REPO_REV = 'stable'
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07007
8# Copyright (C) 2008 Google Inc.
9#
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
13#
14# http://www.apache.org/licenses/LICENSE-2.0
15#
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.
21
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070022# increment this whenever we make important changes to this script
Anthony Kingcc1b1a72015-03-28 19:33:59 +000023VERSION = (1, 21)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070024
25# increment this if the MAINTAINER_KEYS block is modified
Conley Owensbc030842013-07-01 11:05:32 -070026KEYRING_VERSION = (1, 2)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070027MAINTAINER_KEYS = """
28
29 Repo Maintainer <repo@android.kernel.org>
30-----BEGIN PGP PUBLIC KEY BLOCK-----
31Version: GnuPG v1.4.2.2 (GNU/Linux)
32
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
68=CMiZ
69-----END PGP PUBLIC KEY BLOCK-----
Conley Owens55e4d462012-10-01 16:12:28 -070070
71 Conley Owens <cco3@android.com>
72-----BEGIN PGP PUBLIC KEY BLOCK-----
73Version: GnuPG v1.4.11 (GNU/Linux)
74
Conley Owensbc030842013-07-01 11:05:32 -070075mQENBFHRvc8BCADFg45Xx/y6QDC+T7Y/gGc7vx0ww7qfOwIKlAZ9xG3qKunMxo+S
76hPCnzEl3cq+6I1Ww/ndop/HB3N3toPXRCoN8Vs4/Hc7by+SnaLFnacrm+tV5/OgT
77V37Lzt8lhay1Kl+YfpFwHYYpIEBLFV9knyfRXS/428W2qhdzYfvB15/AasRmwmor
78py4NIzSs8UD/SPr1ihqNCdZM76+MQyN5HMYXW/ALZXUFG0pwluHFA7hrfPG74i8C
79zMiP7qvMWIl/r/jtzHioH1dRKgbod+LZsrDJ8mBaqsZaDmNJMhss9g76XvfMyLra
809DI9/iFuBpGzeqBv0hwOGQspLRrEoyTeR6n1ABEBAAG0H0NvbmxleSBPd2VucyA8
81Y2NvM0BhbmRyb2lkLmNvbT6JATgEEwECACIFAlHRvc8CGwMGCwkIBwMCBhUIAgkK
82CwQWAgMBAh4BAheAAAoJEGe35EhpKzgsP6AIAJKJmNtn4l7hkYHKHFSo3egb6RjQ
83zEIP3MFTcu8HFX1kF1ZFbrp7xqurLaE53kEkKuAAvjJDAgI8mcZHP1JyplubqjQA
84xvv84gK+OGP3Xk+QK1ZjUQSbjOpjEiSZpRhWcHci3dgOUH4blJfByHw25hlgHowd
85a/2PrNKZVcJ92YienaxxGjcXEUcd0uYEG2+rwllQigFcnMFDhr9B71MfalRHjFKE
86fmdoypqLrri61YBc59P88Rw2/WUpTQjgNubSqa3A2+CKdaRyaRw+2fdF4TdR0h8W
87zbg+lbaPtJHsV+3mJC7fq26MiJDRJa5ZztpMn8su20gbLgi2ShBOaHAYDDi5AQ0E
88UdG9zwEIAMoOBq+QLNozAhxOOl5GL3StTStGRgPRXINfmViTsihrqGCWBBUfXlUE
89OytC0mYcrDUQev/8ToVoyqw+iGSwDkcSXkrEUCKFtHV/GECWtk1keyHgR10YKI1R
90mquSXoubWGqPeG1PAI74XWaRx8UrL8uCXUtmD8Q5J7mDjKR5NpxaXrwlA0bKsf2E
91Gp9tu1kKauuToZhWHMRMqYSOGikQJwWSFYKT1KdNcOXLQF6+bfoJ6sjVYdwfmNQL
92Ixn8QVhoTDedcqClSWB17VDEFDFa7MmqXZz2qtM3X1R/MUMHqPtegQzBGNhRdnI2
93V45+1Nnx/uuCxDbeI4RbHzujnxDiq70AEQEAAYkBHwQYAQIACQUCUdG9zwIbDAAK
94CRBnt+RIaSs4LNVeB/0Y2pZ8I7gAAcEM0Xw8drr4omg2fUoK1J33ozlA/RxeA/lJ
95I3KnyCDTpXuIeBKPGkdL8uMATC9Z8DnBBajRlftNDVZS3Hz4G09G9QpMojvJkFJV
96By+01Flw/X+eeN8NpqSuLV4W+AjEO8at/VvgKr1AFvBRdZ7GkpI1o6DgPe7ZqX+1
97dzQZt3e13W0rVBb/bUgx9iSLoeWP3aq/k+/GRGOR+S6F6BBSl0SQ2EF2+dIywb1x
98JuinEP+AwLAUZ1Bsx9ISC0Agpk2VeHXPL3FGhroEmoMvBzO0kTFGyoeT7PR/BfKv
99+H/g3HsL2LOB9uoIm8/5p2TTU5ttYCXMHhQZ81AY
100=AUp4
Conley Owens55e4d462012-10-01 16:12:28 -0700101-----END PGP PUBLIC KEY BLOCK-----
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700102"""
103
104GIT = 'git' # our git command
Anthony Kingcc1b1a72015-03-28 19:33:59 +0000105MIN_GIT_VERSION = (1, 7, 2) # minimum supported git version
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700106repodir = '.repo' # name of repo's private directory
Conley Owensc9129d92012-10-01 16:12:28 -0700107S_repo = 'repo' # special repo repository
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700108S_manifests = 'manifests' # special manifest repository
109REPO_MAIN = S_repo + '/main.py' # main script
Chirayu Desai51813df2013-04-16 19:36:09 +0530110MIN_PYTHON_VERSION = (2, 6) # minimum supported python version
Simran Basi8ce50412015-08-28 14:25:44 -0700111GITC_CONFIG_FILE = '/gitc/.config'
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700112
113
David Jamesbf79c662013-12-26 14:20:13 -0800114import errno
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700115import optparse
116import os
117import re
Mitchel Humpheryseb5acc92014-03-12 10:48:15 -0700118import shutil
Sarah Owens60798a32012-10-25 17:53:09 -0700119import stat
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700120import subprocess
121import sys
David Pursehouse59bbb582013-05-17 10:49:33 +0900122
123if sys.version_info[0] == 3:
Sarah Owens1f7627f2012-10-31 09:21:55 -0700124 import urllib.request
125 import urllib.error
126else:
Sarah Owens1f7627f2012-10-31 09:21:55 -0700127 import imp
David Pursehouse59bbb582013-05-17 10:49:33 +0900128 import urllib2
Sarah Owens1f7627f2012-10-31 09:21:55 -0700129 urllib = imp.new_module('urllib')
130 urllib.request = urllib2
131 urllib.error = urllib2
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700132
Conley Owens5e0ee142013-09-26 15:50:49 -0700133
134def _print(*objects, **kwargs):
135 sep = kwargs.get('sep', ' ')
136 end = kwargs.get('end', '\n')
137 out = kwargs.get('file', sys.stdout)
138 out.write(sep.join(objects) + end)
139
140
Chirayu Desai51813df2013-04-16 19:36:09 +0530141# Python version check
142ver = sys.version_info
Chirayu Desai51813df2013-04-16 19:36:09 +0530143if (ver[0], ver[1]) < MIN_PYTHON_VERSION:
Conley Owens5e0ee142013-09-26 15:50:49 -0700144 _print('error: Python version %s unsupported.\n'
145 'Please use Python 2.6 - 2.7 instead.'
146 % sys.version.split(' ')[0], file=sys.stderr)
Chirayu Desai51813df2013-04-16 19:36:09 +0530147 sys.exit(1)
148
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700149home_dot_repo = os.path.expanduser('~/.repoconfig')
150gpg_dir = os.path.join(home_dot_repo, 'gnupg')
151
152extra_args = []
153init_optparse = optparse.OptionParser(usage="repo init -u url [options]")
154
155# Logging
156group = init_optparse.add_option_group('Logging options')
157group.add_option('-q', '--quiet',
158 dest="quiet", action="store_true", default=False,
159 help="be quiet")
160
161# Manifest
162group = init_optparse.add_option_group('Manifest options')
163group.add_option('-u', '--manifest-url',
164 dest='manifest_url',
165 help='manifest repository location', metavar='URL')
166group.add_option('-b', '--manifest-branch',
167 dest='manifest_branch',
168 help='manifest branch or revision', metavar='REVISION')
169group.add_option('-m', '--manifest-name',
170 dest='manifest_name',
171 help='initial manifest file', metavar='NAME.xml')
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800172group.add_option('--mirror',
173 dest='mirror', action='store_true',
David Pursehouse3794a782012-11-15 06:17:30 +0900174 help='create a replica of the remote repositories '
175 'rather than a client working directory')
Shawn O. Pearce88443382010-10-08 10:02:09 +0200176group.add_option('--reference',
177 dest='reference',
178 help='location of mirror directory', metavar='DIR')
Doug Anderson49cd59b2011-06-13 21:42:06 -0700179group.add_option('--depth', type='int', default=None,
180 dest='depth',
181 help='create a shallow clone with given depth; see git clone')
Julien Campergue335f5ef2013-10-16 11:02:35 +0200182group.add_option('--archive',
183 dest='archive', action='store_true',
184 help='checkout an archive instead of a git repository for '
185 'each project. See git archive.')
Colin Cross5acde752012-03-28 20:15:45 -0700186group.add_option('-g', '--groups',
Conley Owens971de8e2012-04-16 10:36:08 -0700187 dest='groups', default='default',
David Holmer0a1c6a12012-11-14 19:19:00 -0500188 help='restrict manifest projects to ones with specified '
189 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]',
Colin Cross5acde752012-03-28 20:15:45 -0700190 metavar='GROUP')
Conley Owensd21720d2012-04-16 11:02:21 -0700191group.add_option('-p', '--platform',
192 dest='platform', default="auto",
Conley Owensc9129d92012-10-01 16:12:28 -0700193 help='restrict manifest projects to ones with a specified '
Conley Owensd21720d2012-04-16 11:02:21 -0700194 'platform group [auto|all|none|linux|darwin|...]',
195 metavar='PLATFORM')
Doug Anderson49cd59b2011-06-13 21:42:06 -0700196
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700197
198# Tool
Shawn O. Pearcefd89b672009-04-18 11:28:57 -0700199group = init_optparse.add_option_group('repo Version options')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700200group.add_option('--repo-url',
201 dest='repo_url',
202 help='repo repository location', metavar='URL')
203group.add_option('--repo-branch',
204 dest='repo_branch',
205 help='repo branch or revision', metavar='REVISION')
206group.add_option('--no-repo-verify',
207 dest='no_repo_verify', action='store_true',
208 help='do not verify repo source code')
209
Victor Boivie841be342011-04-05 11:31:10 +0200210# Other
211group = init_optparse.add_option_group('Other options')
212group.add_option('--config-name',
213 dest='config_name', action="store_true", default=False,
214 help='Always prompt for name/e-mail')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700215
Simran Basi1efc2b42015-08-05 15:04:22 -0700216def _GitcInitOptions(init_optparse):
217 g = init_optparse.add_option_group('GITC options')
218 g.add_option('-f', '--manifest-file',
219 dest='manifest_file',
220 help='Optional manifest file to use for this GITC client.')
221 g.add_option('-c', '--gitc-client',
222 dest='gitc_client',
223 help='The name for the new gitc_client instance.')
224
Simran Basi8ce50412015-08-28 14:25:44 -0700225_gitc_manifest_dir = None
226def get_gitc_manifest_dir():
227 global _gitc_manifest_dir
228 if _gitc_manifest_dir is None:
Dan Willemsen2487cb72015-08-31 15:45:06 -0700229 _gitc_manifest_dir = ''
Simran Basi8ce50412015-08-28 14:25:44 -0700230 try:
231 with open(GITC_CONFIG_FILE, 'r') as gitc_config:
232 for line in gitc_config:
233 match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line)
234 if match:
235 _gitc_manifest_dir = match.group('gitc_manifest_dir')
236 except IOError:
Dan Willemsen2487cb72015-08-31 15:45:06 -0700237 pass
Simran Basi8ce50412015-08-28 14:25:44 -0700238 return _gitc_manifest_dir
239
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700240class CloneFailure(Exception):
241 """Indicate the remote clone of repo itself failed.
242 """
243
244
Simran Basi1efc2b42015-08-05 15:04:22 -0700245def _Init(args, gitc_init=False):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700246 """Installs repo by cloning it over the network.
247 """
Simran Basi1efc2b42015-08-05 15:04:22 -0700248 if gitc_init:
249 _GitcInitOptions(init_optparse)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700250 opt, args = init_optparse.parse_args(args)
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800251 if args:
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700252 init_optparse.print_usage()
253 sys.exit(1)
254
255 url = opt.repo_url
256 if not url:
257 url = REPO_URL
258 extra_args.append('--repo-url=%s' % url)
259
260 branch = opt.repo_branch
261 if not branch:
262 branch = REPO_REV
263 extra_args.append('--repo-branch=%s' % branch)
264
265 if branch.startswith('refs/heads/'):
266 branch = branch[len('refs/heads/'):]
267 if branch.startswith('refs/'):
Conley Owens5e0ee142013-09-26 15:50:49 -0700268 _print("fatal: invalid branch name '%s'" % branch, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700269 raise CloneFailure()
270
David Jamesbf79c662013-12-26 14:20:13 -0800271 try:
Simran Basi1efc2b42015-08-05 15:04:22 -0700272 if gitc_init:
Simran Basi8ce50412015-08-28 14:25:44 -0700273 gitc_manifest_dir = get_gitc_manifest_dir()
274 if not gitc_manifest_dir:
275 _print('error: GITC filesystem is not running. Exiting...',
276 file=sys.stderr)
277 sys.exit(1)
278 client_dir = os.path.join(gitc_manifest_dir, opt.gitc_client)
Simran Basi1efc2b42015-08-05 15:04:22 -0700279 if not os.path.exists(client_dir):
280 os.makedirs(client_dir)
281 os.chdir(client_dir)
282 if os.path.exists(repodir):
283 # This GITC Client has already initialized repo so continue.
284 return
285
David Jamesbf79c662013-12-26 14:20:13 -0800286 os.mkdir(repodir)
287 except OSError as e:
288 if e.errno != errno.EEXIST:
Conley Owens5e0ee142013-09-26 15:50:49 -0700289 _print('fatal: cannot make %s directory: %s'
290 % (repodir, e.strerror), file=sys.stderr)
David Pursehouse3794a782012-11-15 06:17:30 +0900291 # Don't raise CloneFailure; that would delete the
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700292 # name. Instead exit immediately.
293 #
294 sys.exit(1)
295
296 _CheckGitVersion()
297 try:
Conley Owensc9129d92012-10-01 16:12:28 -0700298 if NeedSetupGnuPG():
299 can_verify = SetupGnuPG(opt.quiet)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700300 else:
301 can_verify = True
302
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700303 dst = os.path.abspath(os.path.join(repodir, S_repo))
304 _Clone(url, dst, opt.quiet)
305
306 if can_verify and not opt.no_repo_verify:
307 rev = _Verify(dst, branch, opt.quiet)
308 else:
309 rev = 'refs/remotes/origin/%s^0' % branch
310
311 _Checkout(dst, branch, rev, opt.quiet)
312 except CloneFailure:
313 if opt.quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700314 _print('fatal: repo init failed; run without --quiet to see why',
315 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700316 raise
317
318
Conley Owensff0a3c82014-01-30 14:46:03 -0800319def ParseGitVersion(ver_str):
320 if not ver_str.startswith('git version '):
321 return None
322
323 num_ver_str = ver_str[len('git version '):].strip().split('-')[0]
324 to_tuple = []
325 for num_str in num_ver_str.split('.')[:3]:
326 if num_str.isdigit():
327 to_tuple.append(int(num_str))
328 else:
329 to_tuple.append(0)
330 return tuple(to_tuple)
331
332
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700333def _CheckGitVersion():
334 cmd = [GIT, '--version']
Shawn O. Pearce4fd38ec2012-06-05 07:55:07 -0700335 try:
336 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700337 except OSError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700338 _print(file=sys.stderr)
339 _print("fatal: '%s' is not available" % GIT, file=sys.stderr)
340 _print('fatal: %s' % e, file=sys.stderr)
341 _print(file=sys.stderr)
342 _print('Please make sure %s is installed and in your path.' % GIT,
343 file=sys.stderr)
Shawn O. Pearce4fd38ec2012-06-05 07:55:07 -0700344 raise CloneFailure()
345
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700346 ver_str = proc.stdout.read().strip()
347 proc.stdout.close()
Shawn O. Pearce16191342008-10-28 08:33:34 -0700348 proc.wait()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700349
Conley Owensff0a3c82014-01-30 14:46:03 -0800350 ver_act = ParseGitVersion(ver_str)
351 if ver_act is None:
Conley Owens5e0ee142013-09-26 15:50:49 -0700352 _print('error: "%s" unsupported' % ver_str, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700353 raise CloneFailure()
354
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700355 if ver_act < MIN_GIT_VERSION:
David Pursehouse685f0802012-11-14 08:34:39 +0900356 need = '.'.join(map(str, MIN_GIT_VERSION))
Conley Owens5e0ee142013-09-26 15:50:49 -0700357 _print('fatal: git %s or later required' % need, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700358 raise CloneFailure()
359
360
Conley Owensc9129d92012-10-01 16:12:28 -0700361def NeedSetupGnuPG():
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700362 if not os.path.isdir(home_dot_repo):
363 return True
364
365 kv = os.path.join(home_dot_repo, 'keyring-version')
366 if not os.path.exists(kv):
367 return True
368
369 kv = open(kv).read()
370 if not kv:
371 return True
372
David Pursehouse685f0802012-11-14 08:34:39 +0900373 kv = tuple(map(int, kv.split('.')))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700374 if kv < KEYRING_VERSION:
375 return True
376 return False
377
378
Conley Owensc9129d92012-10-01 16:12:28 -0700379def SetupGnuPG(quiet):
David Jamesbf79c662013-12-26 14:20:13 -0800380 try:
381 os.mkdir(home_dot_repo)
382 except OSError as e:
383 if e.errno != errno.EEXIST:
Conley Owens5e0ee142013-09-26 15:50:49 -0700384 _print('fatal: cannot make %s directory: %s'
385 % (home_dot_repo, e.strerror), file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700386 sys.exit(1)
387
David Jamesbf79c662013-12-26 14:20:13 -0800388 try:
389 os.mkdir(gpg_dir, stat.S_IRWXU)
390 except OSError as e:
391 if e.errno != errno.EEXIST:
Conley Owens5e0ee142013-09-26 15:50:49 -0700392 _print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror),
393 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700394 sys.exit(1)
395
Shawn O. Pearcef18cb762010-12-07 11:41:05 -0800396 env = os.environ.copy()
397 env['GNUPGHOME'] = gpg_dir.encode()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700398
399 cmd = ['gpg', '--import']
400 try:
401 proc = subprocess.Popen(cmd,
402 env = env,
403 stdin = subprocess.PIPE)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700404 except OSError as e:
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700405 if not quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700406 _print('warning: gpg (GnuPG) is not available.', file=sys.stderr)
407 _print('warning: Installing it is strongly encouraged.', file=sys.stderr)
408 _print(file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700409 return False
410
411 proc.stdin.write(MAINTAINER_KEYS)
412 proc.stdin.close()
413
414 if proc.wait() != 0:
Conley Owens5e0ee142013-09-26 15:50:49 -0700415 _print('fatal: registering repo maintainer keys failed', file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700416 sys.exit(1)
Conley Owens5e0ee142013-09-26 15:50:49 -0700417 _print()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700418
419 fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w')
David Pursehouse685f0802012-11-14 08:34:39 +0900420 fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700421 fd.close()
422 return True
423
424
425def _SetConfig(local, name, value):
426 """Set a git configuration option to the specified value.
427 """
428 cmd = [GIT, 'config', name, value]
429 if subprocess.Popen(cmd, cwd = local).wait() != 0:
430 raise CloneFailure()
431
432
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700433def _InitHttp():
434 handlers = []
435
Sarah Owens1f7627f2012-10-31 09:21:55 -0700436 mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700437 try:
438 import netrc
439 n = netrc.netrc()
440 for host in n.hosts:
441 p = n.hosts[host]
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800442 mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
443 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700444 except:
445 pass
Sarah Owens1f7627f2012-10-31 09:21:55 -0700446 handlers.append(urllib.request.HTTPBasicAuthHandler(mgr))
447 handlers.append(urllib.request.HTTPDigestAuthHandler(mgr))
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700448
449 if 'http_proxy' in os.environ:
450 url = os.environ['http_proxy']
Sarah Owens1f7627f2012-10-31 09:21:55 -0700451 handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700452 if 'REPO_CURL_VERBOSE' in os.environ:
Sarah Owens1f7627f2012-10-31 09:21:55 -0700453 handlers.append(urllib.request.HTTPHandler(debuglevel=1))
454 handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
455 urllib.request.install_opener(urllib.request.build_opener(*handlers))
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700456
457def _Fetch(url, local, src, quiet):
458 if not quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700459 _print('Get %s' % url, file=sys.stderr)
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700460
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700461 cmd = [GIT, 'fetch']
462 if quiet:
463 cmd.append('--quiet')
464 err = subprocess.PIPE
465 else:
466 err = None
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700467 cmd.append(src)
468 cmd.append('+refs/heads/*:refs/remotes/origin/*')
469 cmd.append('refs/tags/*:refs/tags/*')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700470
471 proc = subprocess.Popen(cmd, cwd = local, stderr = err)
472 if err:
473 proc.stderr.read()
474 proc.stderr.close()
475 if proc.wait() != 0:
476 raise CloneFailure()
477
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700478def _DownloadBundle(url, local, quiet):
479 if not url.endswith('/'):
480 url += '/'
481 url += 'clone.bundle'
482
483 proc = subprocess.Popen(
484 [GIT, 'config', '--get-regexp', 'url.*.insteadof'],
485 cwd = local,
486 stdout = subprocess.PIPE)
487 for line in proc.stdout:
488 m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line)
489 if m:
490 new_url = m.group(1)
491 old_url = m.group(2)
492 if url.startswith(old_url):
493 url = new_url + url[len(old_url):]
494 break
495 proc.stdout.close()
496 proc.wait()
497
498 if not url.startswith('http:') and not url.startswith('https:'):
499 return False
500
501 dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b')
502 try:
503 try:
Sarah Owens1f7627f2012-10-31 09:21:55 -0700504 r = urllib.request.urlopen(url)
505 except urllib.error.HTTPError as e:
Pascal Bach23387882015-02-13 16:23:12 +0100506 if e.code in [401, 403, 404]:
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700507 return False
Conley Owens5e0ee142013-09-26 15:50:49 -0700508 _print('fatal: Cannot get %s' % url, file=sys.stderr)
509 _print('fatal: HTTP error %s' % e.code, file=sys.stderr)
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700510 raise CloneFailure()
Sarah Owens1f7627f2012-10-31 09:21:55 -0700511 except urllib.error.URLError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700512 _print('fatal: Cannot get %s' % url, file=sys.stderr)
513 _print('fatal: error %s' % e.reason, file=sys.stderr)
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700514 raise CloneFailure()
515 try:
516 if not quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700517 _print('Get %s' % url, file=sys.stderr)
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700518 while True:
519 buf = r.read(8192)
520 if buf == '':
521 return True
522 dest.write(buf)
523 finally:
524 r.close()
525 finally:
526 dest.close()
527
528def _ImportBundle(local):
529 path = os.path.join(local, '.git', 'clone.bundle')
530 try:
531 _Fetch(local, local, path, True)
532 finally:
533 os.remove(path)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700534
535def _Clone(url, local, quiet):
536 """Clones a git repository to a new subdirectory of repodir
537 """
538 try:
539 os.mkdir(local)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700540 except OSError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700541 _print('fatal: cannot make %s directory: %s' % (local, e.strerror),
542 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700543 raise CloneFailure()
544
545 cmd = [GIT, 'init', '--quiet']
546 try:
547 proc = subprocess.Popen(cmd, cwd = local)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700548 except OSError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700549 _print(file=sys.stderr)
550 _print("fatal: '%s' is not available" % GIT, file=sys.stderr)
551 _print('fatal: %s' % e, file=sys.stderr)
552 _print(file=sys.stderr)
553 _print('Please make sure %s is installed and in your path.' % GIT,
Sarah Owenscecd1d82012-11-01 22:59:27 -0700554 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700555 raise CloneFailure()
556 if proc.wait() != 0:
Conley Owens5e0ee142013-09-26 15:50:49 -0700557 _print('fatal: could not create %s' % local, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700558 raise CloneFailure()
559
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700560 _InitHttp()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700561 _SetConfig(local, 'remote.origin.url', url)
562 _SetConfig(local, 'remote.origin.fetch',
563 '+refs/heads/*:refs/remotes/origin/*')
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700564 if _DownloadBundle(url, local, quiet):
565 _ImportBundle(local)
566 else:
567 _Fetch(url, local, 'origin', quiet)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700568
569
570def _Verify(cwd, branch, quiet):
571 """Verify the branch has been signed by a tag.
572 """
573 cmd = [GIT, 'describe', 'origin/%s' % branch]
574 proc = subprocess.Popen(cmd,
575 stdout=subprocess.PIPE,
576 stderr=subprocess.PIPE,
577 cwd = cwd)
578 cur = proc.stdout.read().strip()
579 proc.stdout.close()
580
581 proc.stderr.read()
582 proc.stderr.close()
583
584 if proc.wait() != 0 or not cur:
Conley Owens5e0ee142013-09-26 15:50:49 -0700585 _print(file=sys.stderr)
586 _print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700587 raise CloneFailure()
588
589 m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
590 if m:
591 cur = m.group(1)
592 if not quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700593 _print(file=sys.stderr)
594 _print("info: Ignoring branch '%s'; using tagged release '%s'"
Sarah Owenscecd1d82012-11-01 22:59:27 -0700595 % (branch, cur), file=sys.stderr)
Conley Owens5e0ee142013-09-26 15:50:49 -0700596 _print(file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700597
Shawn O. Pearcef18cb762010-12-07 11:41:05 -0800598 env = os.environ.copy()
599 env['GNUPGHOME'] = gpg_dir.encode()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700600
601 cmd = [GIT, 'tag', '-v', cur]
602 proc = subprocess.Popen(cmd,
603 stdout = subprocess.PIPE,
604 stderr = subprocess.PIPE,
605 cwd = cwd,
606 env = env)
607 out = proc.stdout.read()
608 proc.stdout.close()
609
610 err = proc.stderr.read()
611 proc.stderr.close()
612
613 if proc.wait() != 0:
Conley Owens5e0ee142013-09-26 15:50:49 -0700614 _print(file=sys.stderr)
615 _print(out, file=sys.stderr)
616 _print(err, file=sys.stderr)
617 _print(file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700618 raise CloneFailure()
619 return '%s^0' % cur
620
621
622def _Checkout(cwd, branch, rev, quiet):
623 """Checkout an upstream branch into the repository and track it.
624 """
625 cmd = [GIT, 'update-ref', 'refs/heads/default', rev]
626 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
627 raise CloneFailure()
628
629 _SetConfig(cwd, 'branch.default.remote', 'origin')
630 _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch)
631
632 cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default']
633 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
634 raise CloneFailure()
635
636 cmd = [GIT, 'read-tree', '--reset', '-u']
637 if not quiet:
638 cmd.append('-v')
639 cmd.append('HEAD')
640 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
641 raise CloneFailure()
642
643
644def _FindRepo():
645 """Look for a repo installation, starting at the current directory.
646 """
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200647 curdir = os.getcwd()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700648 repo = None
649
Anthony Newnamdf14a702011-01-09 17:31:57 -0800650 olddir = None
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200651 while curdir != '/' \
652 and curdir != olddir \
Anthony Newnamdf14a702011-01-09 17:31:57 -0800653 and not repo:
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200654 repo = os.path.join(curdir, repodir, REPO_MAIN)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700655 if not os.path.isfile(repo):
656 repo = None
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200657 olddir = curdir
658 curdir = os.path.dirname(curdir)
659 return (repo, os.path.join(curdir, repodir))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700660
661
662class _Options:
663 help = False
664
665
666def _ParseArguments(args):
667 cmd = None
668 opt = _Options()
669 arg = []
670
Sarah Owensa6053d52012-11-01 13:36:50 -0700671 for i in range(len(args)):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700672 a = args[i]
673 if a == '-h' or a == '--help':
674 opt.help = True
675
676 elif not a.startswith('-'):
677 cmd = a
678 arg = args[i + 1:]
679 break
680 return cmd, opt, arg
681
682
683def _Usage():
Conley Owens5e0ee142013-09-26 15:50:49 -0700684 _print(
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700685"""usage: repo COMMAND [ARGS]
686
687repo is not yet installed. Use "repo init" to install it here.
688
689The most commonly used repo commands are:
690
691 init Install repo in the current working directory
692 help Display detailed help on a command
693
694For access to the full online help, install repo ("repo init").
Sarah Owenscecd1d82012-11-01 22:59:27 -0700695""", file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700696 sys.exit(1)
697
698
699def _Help(args):
700 if args:
701 if args[0] == 'init':
702 init_optparse.print_help()
Trond Norbyed3fd5372011-01-03 11:35:15 +0100703 sys.exit(0)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700704 else:
Conley Owens5e0ee142013-09-26 15:50:49 -0700705 _print("error: '%s' is not a bootstrap command.\n"
706 ' For access to online help, install repo ("repo init").'
707 % args[0], file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700708 else:
709 _Usage()
710 sys.exit(1)
711
712
713def _NotInstalled():
Conley Owens5e0ee142013-09-26 15:50:49 -0700714 _print('error: repo is not installed. Use "repo init" to install it here.',
715 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700716 sys.exit(1)
717
718
719def _NoCommands(cmd):
Conley Owens5e0ee142013-09-26 15:50:49 -0700720 _print("""error: command '%s' requires repo to be installed first.
721 Use "repo init" to install it here.""" % cmd, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700722 sys.exit(1)
723
724
725def _RunSelf(wrapper_path):
726 my_dir = os.path.dirname(wrapper_path)
727 my_main = os.path.join(my_dir, 'main.py')
728 my_git = os.path.join(my_dir, '.git')
729
730 if os.path.isfile(my_main) and os.path.isdir(my_git):
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -0700731 for name in ['git_config.py',
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700732 'project.py',
733 'subcmds']:
734 if not os.path.exists(os.path.join(my_dir, name)):
735 return None, None
736 return my_main, my_git
737 return None, None
738
739
740def _SetDefaultsTo(gitdir):
741 global REPO_URL
742 global REPO_REV
743
744 REPO_URL = gitdir
745 proc = subprocess.Popen([GIT,
746 '--git-dir=%s' % gitdir,
747 'symbolic-ref',
748 'HEAD'],
749 stdout = subprocess.PIPE,
750 stderr = subprocess.PIPE)
751 REPO_REV = proc.stdout.read().strip()
752 proc.stdout.close()
753
754 proc.stderr.read()
755 proc.stderr.close()
756
757 if proc.wait() != 0:
Conley Owens5e0ee142013-09-26 15:50:49 -0700758 _print('fatal: %s has no current branch' % gitdir, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700759 sys.exit(1)
760
761
762def main(orig_args):
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200763 repo_main, rel_repo_dir = _FindRepo()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700764 cmd, opt, args = _ParseArguments(orig_args)
765
766 wrapper_path = os.path.abspath(__file__)
767 my_main, my_git = _RunSelf(wrapper_path)
768
Simran Basi8ce50412015-08-28 14:25:44 -0700769 cwd = os.getcwd()
Dan Willemsen2487cb72015-08-31 15:45:06 -0700770 if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()):
Simran Basi8ce50412015-08-28 14:25:44 -0700771 _print('error: repo cannot be used in the GITC local manifest directory.'
772 '\nIf you want to work on this GITC client please rerun this '
773 'command from the corresponding client under /gitc/', file=sys.stderr)
774 sys.exit(1)
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200775 if not repo_main:
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700776 if opt.help:
777 _Usage()
778 if cmd == 'help':
779 _Help(args)
780 if not cmd:
781 _NotInstalled()
Simran Basi1efc2b42015-08-05 15:04:22 -0700782 if cmd == 'init' or cmd == 'gitc-init':
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700783 if my_git:
784 _SetDefaultsTo(my_git)
785 try:
Simran Basi1efc2b42015-08-05 15:04:22 -0700786 _Init(args, gitc_init=(cmd == 'gitc-init'))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700787 except CloneFailure:
Mani Chandelf75870b2014-09-03 13:54:48 +0530788 shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700789 sys.exit(1)
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200790 repo_main, rel_repo_dir = _FindRepo()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700791 else:
792 _NoCommands(cmd)
793
794 if my_main:
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200795 repo_main = my_main
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700796
David Pursehouse685f0802012-11-14 08:34:39 +0900797 ver_str = '.'.join(map(str, VERSION))
anatoly techtonik3a2a59e2013-09-21 19:29:10 +0300798 me = [sys.executable, repo_main,
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200799 '--repo-dir=%s' % rel_repo_dir,
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700800 '--wrapper-version=%s' % ver_str,
801 '--wrapper-path=%s' % wrapper_path,
802 '--']
803 me.extend(orig_args)
804 me.extend(extra_args)
805 try:
anatoly techtonik3a2a59e2013-09-21 19:29:10 +0300806 os.execv(sys.executable, me)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700807 except OSError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700808 _print("fatal: unable to start %s" % repo_main, file=sys.stderr)
809 _print("fatal: %s" % e, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700810 sys.exit(148)
811
812
813if __name__ == '__main__':
Anthony King6efdde92014-05-05 20:37:05 +0100814 if ver[0] == 3:
815 _print('warning: Python 3 support is currently experimental. YMMV.\n'
816 'Please use Python 2.6 - 2.7 instead.',
817 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700818 main(sys.argv[1:])