blob: b7d8024f8c02b9fb4f3325378c1517e2fe9f5e7c [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):
Dan Willemsen9ff2ece2015-08-31 15:45:06 -0700217 init_optparse.set_usage("repo gitc-init -u url -c client [options]")
Simran Basi1efc2b42015-08-05 15:04:22 -0700218 g = init_optparse.add_option_group('GITC options')
219 g.add_option('-f', '--manifest-file',
220 dest='manifest_file',
221 help='Optional manifest file to use for this GITC client.')
222 g.add_option('-c', '--gitc-client',
223 dest='gitc_client',
224 help='The name for the new gitc_client instance.')
225
Simran Basi8ce50412015-08-28 14:25:44 -0700226_gitc_manifest_dir = None
227def get_gitc_manifest_dir():
228 global _gitc_manifest_dir
229 if _gitc_manifest_dir is None:
Dan Willemsen2487cb72015-08-31 15:45:06 -0700230 _gitc_manifest_dir = ''
Simran Basi8ce50412015-08-28 14:25:44 -0700231 try:
232 with open(GITC_CONFIG_FILE, 'r') as gitc_config:
233 for line in gitc_config:
234 match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line)
235 if match:
236 _gitc_manifest_dir = match.group('gitc_manifest_dir')
237 except IOError:
Dan Willemsen2487cb72015-08-31 15:45:06 -0700238 pass
Simran Basi8ce50412015-08-28 14:25:44 -0700239 return _gitc_manifest_dir
240
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700241class CloneFailure(Exception):
242 """Indicate the remote clone of repo itself failed.
243 """
244
245
Simran Basi1efc2b42015-08-05 15:04:22 -0700246def _Init(args, gitc_init=False):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700247 """Installs repo by cloning it over the network.
248 """
Simran Basi1efc2b42015-08-05 15:04:22 -0700249 if gitc_init:
250 _GitcInitOptions(init_optparse)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700251 opt, args = init_optparse.parse_args(args)
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800252 if args:
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700253 init_optparse.print_usage()
254 sys.exit(1)
255
256 url = opt.repo_url
257 if not url:
258 url = REPO_URL
259 extra_args.append('--repo-url=%s' % url)
260
261 branch = opt.repo_branch
262 if not branch:
263 branch = REPO_REV
264 extra_args.append('--repo-branch=%s' % branch)
265
266 if branch.startswith('refs/heads/'):
267 branch = branch[len('refs/heads/'):]
268 if branch.startswith('refs/'):
Conley Owens5e0ee142013-09-26 15:50:49 -0700269 _print("fatal: invalid branch name '%s'" % branch, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700270 raise CloneFailure()
271
David Jamesbf79c662013-12-26 14:20:13 -0800272 try:
Simran Basi1efc2b42015-08-05 15:04:22 -0700273 if gitc_init:
Simran Basi8ce50412015-08-28 14:25:44 -0700274 gitc_manifest_dir = get_gitc_manifest_dir()
275 if not gitc_manifest_dir:
Dan Willemsen9ff2ece2015-08-31 15:45:06 -0700276 _print('fatal: GITC filesystem is not available. Exiting...',
Simran Basi8ce50412015-08-28 14:25:44 -0700277 file=sys.stderr)
278 sys.exit(1)
Dan Willemsen9ff2ece2015-08-31 15:45:06 -0700279 if not opt.gitc_client:
280 _print('fatal: GITC client (-c) is required.', file=sys.stderr)
281 sys.exit(1)
Simran Basi8ce50412015-08-28 14:25:44 -0700282 client_dir = os.path.join(gitc_manifest_dir, opt.gitc_client)
Simran Basi1efc2b42015-08-05 15:04:22 -0700283 if not os.path.exists(client_dir):
284 os.makedirs(client_dir)
285 os.chdir(client_dir)
286 if os.path.exists(repodir):
287 # This GITC Client has already initialized repo so continue.
288 return
289
David Jamesbf79c662013-12-26 14:20:13 -0800290 os.mkdir(repodir)
291 except OSError as e:
292 if e.errno != errno.EEXIST:
Conley Owens5e0ee142013-09-26 15:50:49 -0700293 _print('fatal: cannot make %s directory: %s'
294 % (repodir, e.strerror), file=sys.stderr)
David Pursehouse3794a782012-11-15 06:17:30 +0900295 # Don't raise CloneFailure; that would delete the
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700296 # name. Instead exit immediately.
297 #
298 sys.exit(1)
299
300 _CheckGitVersion()
301 try:
Conley Owensc9129d92012-10-01 16:12:28 -0700302 if NeedSetupGnuPG():
303 can_verify = SetupGnuPG(opt.quiet)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700304 else:
305 can_verify = True
306
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700307 dst = os.path.abspath(os.path.join(repodir, S_repo))
308 _Clone(url, dst, opt.quiet)
309
310 if can_verify and not opt.no_repo_verify:
311 rev = _Verify(dst, branch, opt.quiet)
312 else:
313 rev = 'refs/remotes/origin/%s^0' % branch
314
315 _Checkout(dst, branch, rev, opt.quiet)
316 except CloneFailure:
317 if opt.quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700318 _print('fatal: repo init failed; run without --quiet to see why',
319 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700320 raise
321
322
Conley Owensff0a3c82014-01-30 14:46:03 -0800323def ParseGitVersion(ver_str):
324 if not ver_str.startswith('git version '):
325 return None
326
327 num_ver_str = ver_str[len('git version '):].strip().split('-')[0]
328 to_tuple = []
329 for num_str in num_ver_str.split('.')[:3]:
330 if num_str.isdigit():
331 to_tuple.append(int(num_str))
332 else:
333 to_tuple.append(0)
334 return tuple(to_tuple)
335
336
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700337def _CheckGitVersion():
338 cmd = [GIT, '--version']
Shawn O. Pearce4fd38ec2012-06-05 07:55:07 -0700339 try:
340 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700341 except OSError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700342 _print(file=sys.stderr)
343 _print("fatal: '%s' is not available" % GIT, file=sys.stderr)
344 _print('fatal: %s' % e, file=sys.stderr)
345 _print(file=sys.stderr)
346 _print('Please make sure %s is installed and in your path.' % GIT,
347 file=sys.stderr)
Shawn O. Pearce4fd38ec2012-06-05 07:55:07 -0700348 raise CloneFailure()
349
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700350 ver_str = proc.stdout.read().strip()
351 proc.stdout.close()
Shawn O. Pearce16191342008-10-28 08:33:34 -0700352 proc.wait()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700353
Conley Owensff0a3c82014-01-30 14:46:03 -0800354 ver_act = ParseGitVersion(ver_str)
355 if ver_act is None:
Conley Owens5e0ee142013-09-26 15:50:49 -0700356 _print('error: "%s" unsupported' % ver_str, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700357 raise CloneFailure()
358
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700359 if ver_act < MIN_GIT_VERSION:
David Pursehouse685f0802012-11-14 08:34:39 +0900360 need = '.'.join(map(str, MIN_GIT_VERSION))
Conley Owens5e0ee142013-09-26 15:50:49 -0700361 _print('fatal: git %s or later required' % need, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700362 raise CloneFailure()
363
364
Conley Owensc9129d92012-10-01 16:12:28 -0700365def NeedSetupGnuPG():
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700366 if not os.path.isdir(home_dot_repo):
367 return True
368
369 kv = os.path.join(home_dot_repo, 'keyring-version')
370 if not os.path.exists(kv):
371 return True
372
373 kv = open(kv).read()
374 if not kv:
375 return True
376
David Pursehouse685f0802012-11-14 08:34:39 +0900377 kv = tuple(map(int, kv.split('.')))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700378 if kv < KEYRING_VERSION:
379 return True
380 return False
381
382
Conley Owensc9129d92012-10-01 16:12:28 -0700383def SetupGnuPG(quiet):
David Jamesbf79c662013-12-26 14:20:13 -0800384 try:
385 os.mkdir(home_dot_repo)
386 except OSError as e:
387 if e.errno != errno.EEXIST:
Conley Owens5e0ee142013-09-26 15:50:49 -0700388 _print('fatal: cannot make %s directory: %s'
389 % (home_dot_repo, e.strerror), file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700390 sys.exit(1)
391
David Jamesbf79c662013-12-26 14:20:13 -0800392 try:
393 os.mkdir(gpg_dir, stat.S_IRWXU)
394 except OSError as e:
395 if e.errno != errno.EEXIST:
Conley Owens5e0ee142013-09-26 15:50:49 -0700396 _print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror),
397 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700398 sys.exit(1)
399
Shawn O. Pearcef18cb762010-12-07 11:41:05 -0800400 env = os.environ.copy()
401 env['GNUPGHOME'] = gpg_dir.encode()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700402
403 cmd = ['gpg', '--import']
404 try:
405 proc = subprocess.Popen(cmd,
406 env = env,
407 stdin = subprocess.PIPE)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700408 except OSError as e:
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700409 if not quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700410 _print('warning: gpg (GnuPG) is not available.', file=sys.stderr)
411 _print('warning: Installing it is strongly encouraged.', file=sys.stderr)
412 _print(file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700413 return False
414
415 proc.stdin.write(MAINTAINER_KEYS)
416 proc.stdin.close()
417
418 if proc.wait() != 0:
Conley Owens5e0ee142013-09-26 15:50:49 -0700419 _print('fatal: registering repo maintainer keys failed', file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700420 sys.exit(1)
Conley Owens5e0ee142013-09-26 15:50:49 -0700421 _print()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700422
423 fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w')
David Pursehouse685f0802012-11-14 08:34:39 +0900424 fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700425 fd.close()
426 return True
427
428
429def _SetConfig(local, name, value):
430 """Set a git configuration option to the specified value.
431 """
432 cmd = [GIT, 'config', name, value]
433 if subprocess.Popen(cmd, cwd = local).wait() != 0:
434 raise CloneFailure()
435
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700436
437def _InitHttp():
438 handlers = []
439
Sarah Owens1f7627f2012-10-31 09:21:55 -0700440 mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700441 try:
442 import netrc
443 n = netrc.netrc()
444 for host in n.hosts:
445 p = n.hosts[host]
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800446 mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
447 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700448 except:
449 pass
Sarah Owens1f7627f2012-10-31 09:21:55 -0700450 handlers.append(urllib.request.HTTPBasicAuthHandler(mgr))
451 handlers.append(urllib.request.HTTPDigestAuthHandler(mgr))
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700452
453 if 'http_proxy' in os.environ:
454 url = os.environ['http_proxy']
Sarah Owens1f7627f2012-10-31 09:21:55 -0700455 handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700456 if 'REPO_CURL_VERBOSE' in os.environ:
Sarah Owens1f7627f2012-10-31 09:21:55 -0700457 handlers.append(urllib.request.HTTPHandler(debuglevel=1))
458 handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
459 urllib.request.install_opener(urllib.request.build_opener(*handlers))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700460
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700461def _Fetch(url, local, src, quiet):
462 if not quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700463 _print('Get %s' % url, file=sys.stderr)
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700464
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700465 cmd = [GIT, 'fetch']
466 if quiet:
467 cmd.append('--quiet')
468 err = subprocess.PIPE
469 else:
470 err = None
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700471 cmd.append(src)
472 cmd.append('+refs/heads/*:refs/remotes/origin/*')
473 cmd.append('refs/tags/*:refs/tags/*')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700474
475 proc = subprocess.Popen(cmd, cwd = local, stderr = err)
476 if err:
477 proc.stderr.read()
478 proc.stderr.close()
479 if proc.wait() != 0:
480 raise CloneFailure()
481
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700482def _DownloadBundle(url, local, quiet):
483 if not url.endswith('/'):
484 url += '/'
485 url += 'clone.bundle'
486
487 proc = subprocess.Popen(
488 [GIT, 'config', '--get-regexp', 'url.*.insteadof'],
489 cwd = local,
490 stdout = subprocess.PIPE)
491 for line in proc.stdout:
492 m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line)
493 if m:
494 new_url = m.group(1)
495 old_url = m.group(2)
496 if url.startswith(old_url):
497 url = new_url + url[len(old_url):]
498 break
499 proc.stdout.close()
500 proc.wait()
501
502 if not url.startswith('http:') and not url.startswith('https:'):
503 return False
504
505 dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b')
506 try:
507 try:
Sarah Owens1f7627f2012-10-31 09:21:55 -0700508 r = urllib.request.urlopen(url)
509 except urllib.error.HTTPError as e:
Pascal Bach23387882015-02-13 16:23:12 +0100510 if e.code in [401, 403, 404]:
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700511 return False
Conley Owens5e0ee142013-09-26 15:50:49 -0700512 _print('fatal: Cannot get %s' % url, file=sys.stderr)
513 _print('fatal: HTTP error %s' % e.code, file=sys.stderr)
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700514 raise CloneFailure()
Sarah Owens1f7627f2012-10-31 09:21:55 -0700515 except urllib.error.URLError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700516 _print('fatal: Cannot get %s' % url, file=sys.stderr)
517 _print('fatal: error %s' % e.reason, file=sys.stderr)
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700518 raise CloneFailure()
519 try:
520 if not quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700521 _print('Get %s' % url, file=sys.stderr)
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700522 while True:
523 buf = r.read(8192)
524 if buf == '':
525 return True
526 dest.write(buf)
527 finally:
528 r.close()
529 finally:
530 dest.close()
531
532def _ImportBundle(local):
533 path = os.path.join(local, '.git', 'clone.bundle')
534 try:
535 _Fetch(local, local, path, True)
536 finally:
537 os.remove(path)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700538
539def _Clone(url, local, quiet):
540 """Clones a git repository to a new subdirectory of repodir
541 """
542 try:
543 os.mkdir(local)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700544 except OSError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700545 _print('fatal: cannot make %s directory: %s' % (local, e.strerror),
546 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700547 raise CloneFailure()
548
549 cmd = [GIT, 'init', '--quiet']
550 try:
551 proc = subprocess.Popen(cmd, cwd = local)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700552 except OSError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700553 _print(file=sys.stderr)
554 _print("fatal: '%s' is not available" % GIT, file=sys.stderr)
555 _print('fatal: %s' % e, file=sys.stderr)
556 _print(file=sys.stderr)
557 _print('Please make sure %s is installed and in your path.' % GIT,
Sarah Owenscecd1d82012-11-01 22:59:27 -0700558 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700559 raise CloneFailure()
560 if proc.wait() != 0:
Conley Owens5e0ee142013-09-26 15:50:49 -0700561 _print('fatal: could not create %s' % local, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700562 raise CloneFailure()
563
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700564 _InitHttp()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700565 _SetConfig(local, 'remote.origin.url', url)
566 _SetConfig(local, 'remote.origin.fetch',
567 '+refs/heads/*:refs/remotes/origin/*')
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700568 if _DownloadBundle(url, local, quiet):
569 _ImportBundle(local)
570 else:
571 _Fetch(url, local, 'origin', quiet)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700572
573
574def _Verify(cwd, branch, quiet):
575 """Verify the branch has been signed by a tag.
576 """
577 cmd = [GIT, 'describe', 'origin/%s' % branch]
578 proc = subprocess.Popen(cmd,
579 stdout=subprocess.PIPE,
580 stderr=subprocess.PIPE,
581 cwd = cwd)
582 cur = proc.stdout.read().strip()
583 proc.stdout.close()
584
585 proc.stderr.read()
586 proc.stderr.close()
587
588 if proc.wait() != 0 or not cur:
Conley Owens5e0ee142013-09-26 15:50:49 -0700589 _print(file=sys.stderr)
590 _print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700591 raise CloneFailure()
592
593 m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
594 if m:
595 cur = m.group(1)
596 if not quiet:
Conley Owens5e0ee142013-09-26 15:50:49 -0700597 _print(file=sys.stderr)
598 _print("info: Ignoring branch '%s'; using tagged release '%s'"
Sarah Owenscecd1d82012-11-01 22:59:27 -0700599 % (branch, cur), file=sys.stderr)
Conley Owens5e0ee142013-09-26 15:50:49 -0700600 _print(file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700601
Shawn O. Pearcef18cb762010-12-07 11:41:05 -0800602 env = os.environ.copy()
603 env['GNUPGHOME'] = gpg_dir.encode()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700604
605 cmd = [GIT, 'tag', '-v', cur]
606 proc = subprocess.Popen(cmd,
607 stdout = subprocess.PIPE,
608 stderr = subprocess.PIPE,
609 cwd = cwd,
610 env = env)
611 out = proc.stdout.read()
612 proc.stdout.close()
613
614 err = proc.stderr.read()
615 proc.stderr.close()
616
617 if proc.wait() != 0:
Conley Owens5e0ee142013-09-26 15:50:49 -0700618 _print(file=sys.stderr)
619 _print(out, file=sys.stderr)
620 _print(err, file=sys.stderr)
621 _print(file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700622 raise CloneFailure()
623 return '%s^0' % cur
624
625
626def _Checkout(cwd, branch, rev, quiet):
627 """Checkout an upstream branch into the repository and track it.
628 """
629 cmd = [GIT, 'update-ref', 'refs/heads/default', rev]
630 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
631 raise CloneFailure()
632
633 _SetConfig(cwd, 'branch.default.remote', 'origin')
634 _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch)
635
636 cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default']
637 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
638 raise CloneFailure()
639
640 cmd = [GIT, 'read-tree', '--reset', '-u']
641 if not quiet:
642 cmd.append('-v')
643 cmd.append('HEAD')
644 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
645 raise CloneFailure()
646
647
648def _FindRepo():
649 """Look for a repo installation, starting at the current directory.
650 """
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200651 curdir = os.getcwd()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700652 repo = None
653
Anthony Newnamdf14a702011-01-09 17:31:57 -0800654 olddir = None
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200655 while curdir != '/' \
656 and curdir != olddir \
Anthony Newnamdf14a702011-01-09 17:31:57 -0800657 and not repo:
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200658 repo = os.path.join(curdir, repodir, REPO_MAIN)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700659 if not os.path.isfile(repo):
660 repo = None
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200661 olddir = curdir
662 curdir = os.path.dirname(curdir)
663 return (repo, os.path.join(curdir, repodir))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700664
665
666class _Options:
667 help = False
668
669
670def _ParseArguments(args):
671 cmd = None
672 opt = _Options()
673 arg = []
674
Sarah Owensa6053d52012-11-01 13:36:50 -0700675 for i in range(len(args)):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700676 a = args[i]
677 if a == '-h' or a == '--help':
678 opt.help = True
679
680 elif not a.startswith('-'):
681 cmd = a
682 arg = args[i + 1:]
683 break
684 return cmd, opt, arg
685
686
687def _Usage():
Dan Willemsen9ff2ece2015-08-31 15:45:06 -0700688 gitc_usage = ""
689 if get_gitc_manifest_dir():
690 gitc_usage = " gitc-init Initialize a GITC Client.\n"
691
Conley Owens5e0ee142013-09-26 15:50:49 -0700692 _print(
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700693"""usage: repo COMMAND [ARGS]
694
695repo is not yet installed. Use "repo init" to install it here.
696
697The most commonly used repo commands are:
698
699 init Install repo in the current working directory
Dan Willemsen9ff2ece2015-08-31 15:45:06 -0700700""" + gitc_usage +
701""" help Display detailed help on a command
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700702
703For access to the full online help, install repo ("repo init").
Sarah Owenscecd1d82012-11-01 22:59:27 -0700704""", file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700705 sys.exit(1)
706
707
708def _Help(args):
709 if args:
710 if args[0] == 'init':
711 init_optparse.print_help()
Trond Norbyed3fd5372011-01-03 11:35:15 +0100712 sys.exit(0)
Dan Willemsen9ff2ece2015-08-31 15:45:06 -0700713 elif args[0] == 'gitc-init':
714 _GitcInitOptions(init_optparse)
715 init_optparse.print_help()
716 sys.exit(0)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700717 else:
Conley Owens5e0ee142013-09-26 15:50:49 -0700718 _print("error: '%s' is not a bootstrap command.\n"
719 ' For access to online help, install repo ("repo init").'
720 % args[0], file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700721 else:
722 _Usage()
723 sys.exit(1)
724
725
726def _NotInstalled():
Conley Owens5e0ee142013-09-26 15:50:49 -0700727 _print('error: repo is not installed. Use "repo init" to install it here.',
728 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700729 sys.exit(1)
730
731
732def _NoCommands(cmd):
Conley Owens5e0ee142013-09-26 15:50:49 -0700733 _print("""error: command '%s' requires repo to be installed first.
734 Use "repo init" to install it here.""" % cmd, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700735 sys.exit(1)
736
737
738def _RunSelf(wrapper_path):
739 my_dir = os.path.dirname(wrapper_path)
740 my_main = os.path.join(my_dir, 'main.py')
741 my_git = os.path.join(my_dir, '.git')
742
743 if os.path.isfile(my_main) and os.path.isdir(my_git):
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -0700744 for name in ['git_config.py',
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700745 'project.py',
746 'subcmds']:
747 if not os.path.exists(os.path.join(my_dir, name)):
748 return None, None
749 return my_main, my_git
750 return None, None
751
752
753def _SetDefaultsTo(gitdir):
754 global REPO_URL
755 global REPO_REV
756
757 REPO_URL = gitdir
758 proc = subprocess.Popen([GIT,
759 '--git-dir=%s' % gitdir,
760 'symbolic-ref',
761 'HEAD'],
762 stdout = subprocess.PIPE,
763 stderr = subprocess.PIPE)
764 REPO_REV = proc.stdout.read().strip()
765 proc.stdout.close()
766
767 proc.stderr.read()
768 proc.stderr.close()
769
770 if proc.wait() != 0:
Conley Owens5e0ee142013-09-26 15:50:49 -0700771 _print('fatal: %s has no current branch' % gitdir, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700772 sys.exit(1)
773
774
775def main(orig_args):
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200776 repo_main, rel_repo_dir = _FindRepo()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700777 cmd, opt, args = _ParseArguments(orig_args)
778
779 wrapper_path = os.path.abspath(__file__)
780 my_main, my_git = _RunSelf(wrapper_path)
781
Simran Basi8ce50412015-08-28 14:25:44 -0700782 cwd = os.getcwd()
Dan Willemsen2487cb72015-08-31 15:45:06 -0700783 if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()):
Simran Basi8ce50412015-08-28 14:25:44 -0700784 _print('error: repo cannot be used in the GITC local manifest directory.'
785 '\nIf you want to work on this GITC client please rerun this '
786 'command from the corresponding client under /gitc/', file=sys.stderr)
787 sys.exit(1)
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200788 if not repo_main:
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700789 if opt.help:
790 _Usage()
791 if cmd == 'help':
792 _Help(args)
793 if not cmd:
794 _NotInstalled()
Simran Basi1efc2b42015-08-05 15:04:22 -0700795 if cmd == 'init' or cmd == 'gitc-init':
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700796 if my_git:
797 _SetDefaultsTo(my_git)
798 try:
Simran Basi1efc2b42015-08-05 15:04:22 -0700799 _Init(args, gitc_init=(cmd == 'gitc-init'))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700800 except CloneFailure:
Mani Chandelf75870b2014-09-03 13:54:48 +0530801 shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700802 sys.exit(1)
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200803 repo_main, rel_repo_dir = _FindRepo()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700804 else:
805 _NoCommands(cmd)
806
807 if my_main:
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200808 repo_main = my_main
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700809
David Pursehouse685f0802012-11-14 08:34:39 +0900810 ver_str = '.'.join(map(str, VERSION))
anatoly techtonik3a2a59e2013-09-21 19:29:10 +0300811 me = [sys.executable, repo_main,
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200812 '--repo-dir=%s' % rel_repo_dir,
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700813 '--wrapper-version=%s' % ver_str,
814 '--wrapper-path=%s' % wrapper_path,
815 '--']
816 me.extend(orig_args)
817 me.extend(extra_args)
818 try:
anatoly techtonik3a2a59e2013-09-21 19:29:10 +0300819 os.execv(sys.executable, me)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700820 except OSError as e:
Conley Owens5e0ee142013-09-26 15:50:49 -0700821 _print("fatal: unable to start %s" % repo_main, file=sys.stderr)
822 _print("fatal: %s" % e, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700823 sys.exit(148)
824
825
826if __name__ == '__main__':
Anthony King6efdde92014-05-05 20:37:05 +0100827 if ver[0] == 3:
828 _print('warning: Python 3 support is currently experimental. YMMV.\n'
829 'Please use Python 2.6 - 2.7 instead.',
830 file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700831 main(sys.argv[1:])