David Pursehouse | 8898e2f | 2012-11-14 07:51:03 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 2 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 3 | # repo default configuration |
| 4 | # |
Mark E. Hamilton | 5553628 | 2016-02-03 15:49:43 -0700 | [diff] [blame] | 5 | import os |
| 6 | REPO_URL = os.environ.get('REPO_URL', None) |
| 7 | if not REPO_URL: |
| 8 | REPO_URL = 'https://gerrit.googlesource.com/git-repo' |
David Pursehouse | 8f62fb7 | 2012-11-14 12:09:38 +0900 | [diff] [blame] | 9 | REPO_REV = 'stable' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 10 | |
| 11 | # Copyright (C) 2008 Google Inc. |
| 12 | # |
| 13 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | # you may not use this file except in compliance with the License. |
| 15 | # You may obtain a copy of the License at |
| 16 | # |
| 17 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | # |
| 19 | # Unless required by applicable law or agreed to in writing, software |
| 20 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | # See the License for the specific language governing permissions and |
| 23 | # limitations under the License. |
| 24 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 25 | # increment this whenever we make important changes to this script |
David Pursehouse | c4c2b06 | 2016-08-17 13:16:31 +0900 | [diff] [blame] | 26 | VERSION = (1, 23) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 27 | |
| 28 | # increment this if the MAINTAINER_KEYS block is modified |
Conley Owens | bc03084 | 2013-07-01 11:05:32 -0700 | [diff] [blame] | 29 | KEYRING_VERSION = (1, 2) |
Mike Frysinger | e443365 | 2016-09-13 18:06:07 -0400 | [diff] [blame] | 30 | |
| 31 | # Each individual key entry is created by using: |
| 32 | # gpg --armor --export keyid |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 33 | MAINTAINER_KEYS = """ |
| 34 | |
| 35 | Repo Maintainer <repo@android.kernel.org> |
| 36 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 37 | Version: GnuPG v1.4.2.2 (GNU/Linux) |
| 38 | |
| 39 | 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 |
| 74 | =CMiZ |
| 75 | -----END PGP PUBLIC KEY BLOCK----- |
Conley Owens | 55e4d46 | 2012-10-01 16:12:28 -0700 | [diff] [blame] | 76 | |
| 77 | Conley Owens <cco3@android.com> |
| 78 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 79 | Version: GnuPG v1.4.11 (GNU/Linux) |
| 80 | |
Conley Owens | bc03084 | 2013-07-01 11:05:32 -0700 | [diff] [blame] | 81 | mQENBFHRvc8BCADFg45Xx/y6QDC+T7Y/gGc7vx0ww7qfOwIKlAZ9xG3qKunMxo+S |
| 82 | hPCnzEl3cq+6I1Ww/ndop/HB3N3toPXRCoN8Vs4/Hc7by+SnaLFnacrm+tV5/OgT |
| 83 | V37Lzt8lhay1Kl+YfpFwHYYpIEBLFV9knyfRXS/428W2qhdzYfvB15/AasRmwmor |
| 84 | py4NIzSs8UD/SPr1ihqNCdZM76+MQyN5HMYXW/ALZXUFG0pwluHFA7hrfPG74i8C |
| 85 | zMiP7qvMWIl/r/jtzHioH1dRKgbod+LZsrDJ8mBaqsZaDmNJMhss9g76XvfMyLra |
| 86 | 9DI9/iFuBpGzeqBv0hwOGQspLRrEoyTeR6n1ABEBAAG0H0NvbmxleSBPd2VucyA8 |
| 87 | Y2NvM0BhbmRyb2lkLmNvbT6JATgEEwECACIFAlHRvc8CGwMGCwkIBwMCBhUIAgkK |
| 88 | CwQWAgMBAh4BAheAAAoJEGe35EhpKzgsP6AIAJKJmNtn4l7hkYHKHFSo3egb6RjQ |
| 89 | zEIP3MFTcu8HFX1kF1ZFbrp7xqurLaE53kEkKuAAvjJDAgI8mcZHP1JyplubqjQA |
| 90 | xvv84gK+OGP3Xk+QK1ZjUQSbjOpjEiSZpRhWcHci3dgOUH4blJfByHw25hlgHowd |
| 91 | a/2PrNKZVcJ92YienaxxGjcXEUcd0uYEG2+rwllQigFcnMFDhr9B71MfalRHjFKE |
| 92 | fmdoypqLrri61YBc59P88Rw2/WUpTQjgNubSqa3A2+CKdaRyaRw+2fdF4TdR0h8W |
| 93 | zbg+lbaPtJHsV+3mJC7fq26MiJDRJa5ZztpMn8su20gbLgi2ShBOaHAYDDi5AQ0E |
| 94 | UdG9zwEIAMoOBq+QLNozAhxOOl5GL3StTStGRgPRXINfmViTsihrqGCWBBUfXlUE |
| 95 | OytC0mYcrDUQev/8ToVoyqw+iGSwDkcSXkrEUCKFtHV/GECWtk1keyHgR10YKI1R |
| 96 | mquSXoubWGqPeG1PAI74XWaRx8UrL8uCXUtmD8Q5J7mDjKR5NpxaXrwlA0bKsf2E |
| 97 | Gp9tu1kKauuToZhWHMRMqYSOGikQJwWSFYKT1KdNcOXLQF6+bfoJ6sjVYdwfmNQL |
| 98 | Ixn8QVhoTDedcqClSWB17VDEFDFa7MmqXZz2qtM3X1R/MUMHqPtegQzBGNhRdnI2 |
| 99 | V45+1Nnx/uuCxDbeI4RbHzujnxDiq70AEQEAAYkBHwQYAQIACQUCUdG9zwIbDAAK |
| 100 | CRBnt+RIaSs4LNVeB/0Y2pZ8I7gAAcEM0Xw8drr4omg2fUoK1J33ozlA/RxeA/lJ |
| 101 | I3KnyCDTpXuIeBKPGkdL8uMATC9Z8DnBBajRlftNDVZS3Hz4G09G9QpMojvJkFJV |
| 102 | By+01Flw/X+eeN8NpqSuLV4W+AjEO8at/VvgKr1AFvBRdZ7GkpI1o6DgPe7ZqX+1 |
| 103 | dzQZt3e13W0rVBb/bUgx9iSLoeWP3aq/k+/GRGOR+S6F6BBSl0SQ2EF2+dIywb1x |
| 104 | JuinEP+AwLAUZ1Bsx9ISC0Agpk2VeHXPL3FGhroEmoMvBzO0kTFGyoeT7PR/BfKv |
| 105 | +H/g3HsL2LOB9uoIm8/5p2TTU5ttYCXMHhQZ81AY |
| 106 | =AUp4 |
Conley Owens | 55e4d46 | 2012-10-01 16:12:28 -0700 | [diff] [blame] | 107 | -----END PGP PUBLIC KEY BLOCK----- |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 108 | """ |
| 109 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 110 | GIT = 'git' # our git command |
| 111 | MIN_GIT_VERSION = (1, 7, 2) # minimum supported git version |
| 112 | repodir = '.repo' # name of repo's private directory |
| 113 | S_repo = 'repo' # special repo repository |
| 114 | S_manifests = 'manifests' # special manifest repository |
| 115 | REPO_MAIN = S_repo + '/main.py' # main script |
| 116 | MIN_PYTHON_VERSION = (2, 6) # minimum supported python version |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 117 | GITC_CONFIG_FILE = '/gitc/.config' |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 118 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 119 | |
| 120 | |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 121 | import errno |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 122 | import optparse |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 123 | import re |
Mitchel Humpherys | eb5acc9 | 2014-03-12 10:48:15 -0700 | [diff] [blame] | 124 | import shutil |
Sarah Owens | 60798a3 | 2012-10-25 17:53:09 -0700 | [diff] [blame] | 125 | import stat |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 126 | import subprocess |
| 127 | import sys |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 128 | |
| 129 | if sys.version_info[0] == 3: |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 130 | import urllib.request |
| 131 | import urllib.error |
| 132 | else: |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 133 | import imp |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 134 | import urllib2 |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 135 | urllib = imp.new_module('urllib') |
| 136 | urllib.request = urllib2 |
| 137 | urllib.error = urllib2 |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 138 | |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 139 | |
| 140 | def _print(*objects, **kwargs): |
| 141 | sep = kwargs.get('sep', ' ') |
| 142 | end = kwargs.get('end', '\n') |
| 143 | out = kwargs.get('file', sys.stdout) |
| 144 | out.write(sep.join(objects) + end) |
| 145 | |
| 146 | |
Chirayu Desai | 51813df | 2013-04-16 19:36:09 +0530 | [diff] [blame] | 147 | # Python version check |
| 148 | ver = sys.version_info |
Chirayu Desai | 51813df | 2013-04-16 19:36:09 +0530 | [diff] [blame] | 149 | if (ver[0], ver[1]) < MIN_PYTHON_VERSION: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 150 | _print('error: Python version %s unsupported.\n' |
| 151 | 'Please use Python 2.6 - 2.7 instead.' |
| 152 | % sys.version.split(' ')[0], file=sys.stderr) |
Chirayu Desai | 51813df | 2013-04-16 19:36:09 +0530 | [diff] [blame] | 153 | sys.exit(1) |
| 154 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 155 | home_dot_repo = os.path.expanduser('~/.repoconfig') |
| 156 | gpg_dir = os.path.join(home_dot_repo, 'gnupg') |
| 157 | |
| 158 | extra_args = [] |
| 159 | init_optparse = optparse.OptionParser(usage="repo init -u url [options]") |
| 160 | |
| 161 | # Logging |
| 162 | group = init_optparse.add_option_group('Logging options') |
| 163 | group.add_option('-q', '--quiet', |
| 164 | dest="quiet", action="store_true", default=False, |
| 165 | help="be quiet") |
| 166 | |
| 167 | # Manifest |
| 168 | group = init_optparse.add_option_group('Manifest options') |
| 169 | group.add_option('-u', '--manifest-url', |
| 170 | dest='manifest_url', |
| 171 | help='manifest repository location', metavar='URL') |
| 172 | group.add_option('-b', '--manifest-branch', |
| 173 | dest='manifest_branch', |
| 174 | help='manifest branch or revision', metavar='REVISION') |
| 175 | group.add_option('-m', '--manifest-name', |
| 176 | dest='manifest_name', |
| 177 | help='initial manifest file', metavar='NAME.xml') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 178 | group.add_option('--mirror', |
| 179 | dest='mirror', action='store_true', |
David Pursehouse | 3794a78 | 2012-11-15 06:17:30 +0900 | [diff] [blame] | 180 | help='create a replica of the remote repositories ' |
| 181 | 'rather than a client working directory') |
Shawn O. Pearce | 8844338 | 2010-10-08 10:02:09 +0200 | [diff] [blame] | 182 | group.add_option('--reference', |
| 183 | dest='reference', |
| 184 | help='location of mirror directory', metavar='DIR') |
Doug Anderson | 49cd59b | 2011-06-13 21:42:06 -0700 | [diff] [blame] | 185 | group.add_option('--depth', type='int', default=None, |
| 186 | dest='depth', |
| 187 | help='create a shallow clone with given depth; see git clone') |
Julien Campergue | 335f5ef | 2013-10-16 11:02:35 +0200 | [diff] [blame] | 188 | group.add_option('--archive', |
| 189 | dest='archive', action='store_true', |
| 190 | help='checkout an archive instead of a git repository for ' |
| 191 | 'each project. See git archive.') |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 192 | group.add_option('-g', '--groups', |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 193 | dest='groups', default='default', |
David Holmer | 0a1c6a1 | 2012-11-14 19:19:00 -0500 | [diff] [blame] | 194 | help='restrict manifest projects to ones with specified ' |
| 195 | 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]', |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 196 | metavar='GROUP') |
Conley Owens | d21720d | 2012-04-16 11:02:21 -0700 | [diff] [blame] | 197 | group.add_option('-p', '--platform', |
| 198 | dest='platform', default="auto", |
Conley Owens | c9129d9 | 2012-10-01 16:12:28 -0700 | [diff] [blame] | 199 | help='restrict manifest projects to ones with a specified ' |
Conley Owens | d21720d | 2012-04-16 11:02:21 -0700 | [diff] [blame] | 200 | 'platform group [auto|all|none|linux|darwin|...]', |
| 201 | metavar='PLATFORM') |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 202 | group.add_option('--no-clone-bundle', |
| 203 | dest='no_clone_bundle', action='store_true', |
| 204 | help='disable use of /clone.bundle on HTTP/HTTPS') |
Doug Anderson | 49cd59b | 2011-06-13 21:42:06 -0700 | [diff] [blame] | 205 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 206 | |
| 207 | # Tool |
Shawn O. Pearce | fd89b67 | 2009-04-18 11:28:57 -0700 | [diff] [blame] | 208 | group = init_optparse.add_option_group('repo Version options') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 209 | group.add_option('--repo-url', |
| 210 | dest='repo_url', |
| 211 | help='repo repository location', metavar='URL') |
| 212 | group.add_option('--repo-branch', |
| 213 | dest='repo_branch', |
| 214 | help='repo branch or revision', metavar='REVISION') |
| 215 | group.add_option('--no-repo-verify', |
| 216 | dest='no_repo_verify', action='store_true', |
| 217 | help='do not verify repo source code') |
| 218 | |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 219 | # Other |
| 220 | group = init_optparse.add_option_group('Other options') |
| 221 | group.add_option('--config-name', |
| 222 | dest='config_name', action="store_true", default=False, |
| 223 | help='Always prompt for name/e-mail') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 224 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 225 | |
| 226 | def _GitcInitOptions(init_optparse_arg): |
| 227 | init_optparse_arg.set_usage("repo gitc-init -u url -c client [options]") |
| 228 | g = init_optparse_arg.add_option_group('GITC options') |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 229 | g.add_option('-f', '--manifest-file', |
| 230 | dest='manifest_file', |
| 231 | help='Optional manifest file to use for this GITC client.') |
| 232 | g.add_option('-c', '--gitc-client', |
| 233 | dest='gitc_client', |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 234 | help='The name of the gitc_client instance to create or modify.') |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 235 | |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 236 | _gitc_manifest_dir = None |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 237 | |
| 238 | |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 239 | def get_gitc_manifest_dir(): |
| 240 | global _gitc_manifest_dir |
| 241 | if _gitc_manifest_dir is None: |
Dan Willemsen | 2487cb7 | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 242 | _gitc_manifest_dir = '' |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 243 | try: |
| 244 | with open(GITC_CONFIG_FILE, 'r') as gitc_config: |
| 245 | for line in gitc_config: |
| 246 | match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line) |
| 247 | if match: |
| 248 | _gitc_manifest_dir = match.group('gitc_manifest_dir') |
| 249 | except IOError: |
Dan Willemsen | 2487cb7 | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 250 | pass |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 251 | return _gitc_manifest_dir |
| 252 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 253 | |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 254 | def gitc_parse_clientdir(gitc_fs_path): |
| 255 | """Parse a path in the GITC FS and return its client name. |
| 256 | |
| 257 | @param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR. |
| 258 | |
| 259 | @returns: The GITC client name |
| 260 | """ |
| 261 | if gitc_fs_path == GITC_FS_ROOT_DIR: |
| 262 | return None |
| 263 | if not gitc_fs_path.startswith(GITC_FS_ROOT_DIR): |
| 264 | manifest_dir = get_gitc_manifest_dir() |
| 265 | if manifest_dir == '': |
| 266 | return None |
| 267 | if manifest_dir[-1] != '/': |
| 268 | manifest_dir += '/' |
| 269 | if gitc_fs_path == manifest_dir: |
| 270 | return None |
| 271 | if not gitc_fs_path.startswith(manifest_dir): |
| 272 | return None |
| 273 | return gitc_fs_path.split(manifest_dir)[1].split('/')[0] |
| 274 | return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0] |
| 275 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 276 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 277 | class CloneFailure(Exception): |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 279 | """Indicate the remote clone of repo itself failed. |
| 280 | """ |
| 281 | |
| 282 | |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 283 | def _Init(args, gitc_init=False): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 284 | """Installs repo by cloning it over the network. |
| 285 | """ |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 286 | if gitc_init: |
| 287 | _GitcInitOptions(init_optparse) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 288 | opt, args = init_optparse.parse_args(args) |
Xiaodong Xu | ae0a36c | 2012-01-31 11:10:09 +0800 | [diff] [blame] | 289 | if args: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 290 | init_optparse.print_usage() |
| 291 | sys.exit(1) |
| 292 | |
| 293 | url = opt.repo_url |
| 294 | if not url: |
| 295 | url = REPO_URL |
| 296 | extra_args.append('--repo-url=%s' % url) |
| 297 | |
| 298 | branch = opt.repo_branch |
| 299 | if not branch: |
| 300 | branch = REPO_REV |
| 301 | extra_args.append('--repo-branch=%s' % branch) |
| 302 | |
| 303 | if branch.startswith('refs/heads/'): |
| 304 | branch = branch[len('refs/heads/'):] |
| 305 | if branch.startswith('refs/'): |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 306 | _print("fatal: invalid branch name '%s'" % branch, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 307 | raise CloneFailure() |
| 308 | |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 309 | try: |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 310 | if gitc_init: |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 311 | gitc_manifest_dir = get_gitc_manifest_dir() |
| 312 | if not gitc_manifest_dir: |
Dan Willemsen | 9ff2ece | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 313 | _print('fatal: GITC filesystem is not available. Exiting...', |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 314 | file=sys.stderr) |
| 315 | sys.exit(1) |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 316 | gitc_client = opt.gitc_client |
| 317 | if not gitc_client: |
| 318 | gitc_client = gitc_parse_clientdir(os.getcwd()) |
| 319 | if not gitc_client: |
Dan Willemsen | 9ff2ece | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 320 | _print('fatal: GITC client (-c) is required.', file=sys.stderr) |
| 321 | sys.exit(1) |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 322 | client_dir = os.path.join(gitc_manifest_dir, gitc_client) |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 323 | if not os.path.exists(client_dir): |
| 324 | os.makedirs(client_dir) |
| 325 | os.chdir(client_dir) |
| 326 | if os.path.exists(repodir): |
| 327 | # This GITC Client has already initialized repo so continue. |
| 328 | return |
| 329 | |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 330 | os.mkdir(repodir) |
| 331 | except OSError as e: |
| 332 | if e.errno != errno.EEXIST: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 333 | _print('fatal: cannot make %s directory: %s' |
| 334 | % (repodir, e.strerror), file=sys.stderr) |
David Pursehouse | 3794a78 | 2012-11-15 06:17:30 +0900 | [diff] [blame] | 335 | # Don't raise CloneFailure; that would delete the |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 336 | # name. Instead exit immediately. |
| 337 | # |
| 338 | sys.exit(1) |
| 339 | |
| 340 | _CheckGitVersion() |
| 341 | try: |
Conley Owens | c9129d9 | 2012-10-01 16:12:28 -0700 | [diff] [blame] | 342 | if NeedSetupGnuPG(): |
| 343 | can_verify = SetupGnuPG(opt.quiet) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 344 | else: |
| 345 | can_verify = True |
| 346 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 347 | dst = os.path.abspath(os.path.join(repodir, S_repo)) |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 348 | _Clone(url, dst, opt.quiet, not opt.no_clone_bundle) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 349 | |
Sebastian Schuberth | 27226e7 | 2016-10-28 14:27:43 +0200 | [diff] [blame] | 350 | if not os.path.isfile('%s/repo' % dst): |
| 351 | _print("warning: '%s' does not look like a git-repo repository, is " |
| 352 | "REPO_URL set correctly?" % url, file=sys.stderr) |
| 353 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 354 | if can_verify and not opt.no_repo_verify: |
| 355 | rev = _Verify(dst, branch, opt.quiet) |
| 356 | else: |
| 357 | rev = 'refs/remotes/origin/%s^0' % branch |
| 358 | |
| 359 | _Checkout(dst, branch, rev, opt.quiet) |
| 360 | except CloneFailure: |
| 361 | if opt.quiet: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 362 | _print('fatal: repo init failed; run without --quiet to see why', |
| 363 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 364 | raise |
| 365 | |
| 366 | |
Conley Owens | ff0a3c8 | 2014-01-30 14:46:03 -0800 | [diff] [blame] | 367 | def ParseGitVersion(ver_str): |
| 368 | if not ver_str.startswith('git version '): |
| 369 | return None |
| 370 | |
| 371 | num_ver_str = ver_str[len('git version '):].strip().split('-')[0] |
| 372 | to_tuple = [] |
| 373 | for num_str in num_ver_str.split('.')[:3]: |
| 374 | if num_str.isdigit(): |
| 375 | to_tuple.append(int(num_str)) |
| 376 | else: |
| 377 | to_tuple.append(0) |
| 378 | return tuple(to_tuple) |
| 379 | |
| 380 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 381 | def _CheckGitVersion(): |
| 382 | cmd = [GIT, '--version'] |
Shawn O. Pearce | 4fd38ec | 2012-06-05 07:55:07 -0700 | [diff] [blame] | 383 | try: |
| 384 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 385 | except OSError as e: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 386 | _print(file=sys.stderr) |
| 387 | _print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
| 388 | _print('fatal: %s' % e, file=sys.stderr) |
| 389 | _print(file=sys.stderr) |
| 390 | _print('Please make sure %s is installed and in your path.' % GIT, |
| 391 | file=sys.stderr) |
Shawn O. Pearce | 4fd38ec | 2012-06-05 07:55:07 -0700 | [diff] [blame] | 392 | raise CloneFailure() |
| 393 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 394 | ver_str = proc.stdout.read().strip() |
| 395 | proc.stdout.close() |
Shawn O. Pearce | 1619134 | 2008-10-28 08:33:34 -0700 | [diff] [blame] | 396 | proc.wait() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 397 | |
Conley Owens | ff0a3c8 | 2014-01-30 14:46:03 -0800 | [diff] [blame] | 398 | ver_act = ParseGitVersion(ver_str) |
| 399 | if ver_act is None: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 400 | _print('error: "%s" unsupported' % ver_str, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 401 | raise CloneFailure() |
| 402 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 403 | if ver_act < MIN_GIT_VERSION: |
David Pursehouse | 685f080 | 2012-11-14 08:34:39 +0900 | [diff] [blame] | 404 | need = '.'.join(map(str, MIN_GIT_VERSION)) |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 405 | _print('fatal: git %s or later required' % need, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 406 | raise CloneFailure() |
| 407 | |
| 408 | |
Conley Owens | c9129d9 | 2012-10-01 16:12:28 -0700 | [diff] [blame] | 409 | def NeedSetupGnuPG(): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 410 | if not os.path.isdir(home_dot_repo): |
| 411 | return True |
| 412 | |
| 413 | kv = os.path.join(home_dot_repo, 'keyring-version') |
| 414 | if not os.path.exists(kv): |
| 415 | return True |
| 416 | |
| 417 | kv = open(kv).read() |
| 418 | if not kv: |
| 419 | return True |
| 420 | |
David Pursehouse | 685f080 | 2012-11-14 08:34:39 +0900 | [diff] [blame] | 421 | kv = tuple(map(int, kv.split('.'))) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 422 | if kv < KEYRING_VERSION: |
| 423 | return True |
| 424 | return False |
| 425 | |
| 426 | |
Conley Owens | c9129d9 | 2012-10-01 16:12:28 -0700 | [diff] [blame] | 427 | def SetupGnuPG(quiet): |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 428 | try: |
| 429 | os.mkdir(home_dot_repo) |
| 430 | except OSError as e: |
| 431 | if e.errno != errno.EEXIST: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 432 | _print('fatal: cannot make %s directory: %s' |
| 433 | % (home_dot_repo, e.strerror), file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 434 | sys.exit(1) |
| 435 | |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 436 | try: |
| 437 | os.mkdir(gpg_dir, stat.S_IRWXU) |
| 438 | except OSError as e: |
| 439 | if e.errno != errno.EEXIST: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 440 | _print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror), |
| 441 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 442 | sys.exit(1) |
| 443 | |
Shawn O. Pearce | f18cb76 | 2010-12-07 11:41:05 -0800 | [diff] [blame] | 444 | env = os.environ.copy() |
Dāvis Mosāns | 631d0ec | 2016-07-16 21:11:11 +0300 | [diff] [blame] | 445 | try: |
| 446 | env['GNUPGHOME'] = gpg_dir |
| 447 | except UnicodeEncodeError: |
| 448 | env['GNUPGHOME'] = gpg_dir.encode() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 449 | |
| 450 | cmd = ['gpg', '--import'] |
| 451 | try: |
| 452 | proc = subprocess.Popen(cmd, |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 453 | env=env, |
| 454 | stdin=subprocess.PIPE) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 455 | except OSError as e: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 456 | if not quiet: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 457 | _print('warning: gpg (GnuPG) is not available.', file=sys.stderr) |
| 458 | _print('warning: Installing it is strongly encouraged.', file=sys.stderr) |
| 459 | _print(file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 460 | return False |
| 461 | |
| 462 | proc.stdin.write(MAINTAINER_KEYS) |
| 463 | proc.stdin.close() |
| 464 | |
| 465 | if proc.wait() != 0: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 466 | _print('fatal: registering repo maintainer keys failed', file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 467 | sys.exit(1) |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 468 | _print() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 469 | |
| 470 | fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w') |
David Pursehouse | 685f080 | 2012-11-14 08:34:39 +0900 | [diff] [blame] | 471 | fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 472 | fd.close() |
| 473 | return True |
| 474 | |
| 475 | |
| 476 | def _SetConfig(local, name, value): |
| 477 | """Set a git configuration option to the specified value. |
| 478 | """ |
| 479 | cmd = [GIT, 'config', name, value] |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 480 | if subprocess.Popen(cmd, cwd=local).wait() != 0: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 481 | raise CloneFailure() |
| 482 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 483 | |
| 484 | def _InitHttp(): |
| 485 | handlers = [] |
| 486 | |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 487 | mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 488 | try: |
| 489 | import netrc |
| 490 | n = netrc.netrc() |
| 491 | for host in n.hosts: |
| 492 | p = n.hosts[host] |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 493 | mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2]) |
Xiaodong Xu | ae0a36c | 2012-01-31 11:10:09 +0800 | [diff] [blame] | 494 | mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2]) |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 495 | except: # pylint: disable=bare-except |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 496 | pass |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 497 | handlers.append(urllib.request.HTTPBasicAuthHandler(mgr)) |
| 498 | handlers.append(urllib.request.HTTPDigestAuthHandler(mgr)) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 499 | |
| 500 | if 'http_proxy' in os.environ: |
| 501 | url = os.environ['http_proxy'] |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 502 | handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url})) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 503 | if 'REPO_CURL_VERBOSE' in os.environ: |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 504 | handlers.append(urllib.request.HTTPHandler(debuglevel=1)) |
| 505 | handlers.append(urllib.request.HTTPSHandler(debuglevel=1)) |
| 506 | urllib.request.install_opener(urllib.request.build_opener(*handlers)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 507 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 508 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 509 | def _Fetch(url, local, src, quiet): |
| 510 | if not quiet: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 511 | _print('Get %s' % url, file=sys.stderr) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 512 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 513 | cmd = [GIT, 'fetch'] |
| 514 | if quiet: |
| 515 | cmd.append('--quiet') |
| 516 | err = subprocess.PIPE |
| 517 | else: |
| 518 | err = None |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 519 | cmd.append(src) |
| 520 | cmd.append('+refs/heads/*:refs/remotes/origin/*') |
| 521 | cmd.append('refs/tags/*:refs/tags/*') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 522 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 523 | proc = subprocess.Popen(cmd, cwd=local, stderr=err) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 524 | if err: |
| 525 | proc.stderr.read() |
| 526 | proc.stderr.close() |
| 527 | if proc.wait() != 0: |
| 528 | raise CloneFailure() |
| 529 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 530 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 531 | def _DownloadBundle(url, local, quiet): |
| 532 | if not url.endswith('/'): |
| 533 | url += '/' |
| 534 | url += 'clone.bundle' |
| 535 | |
| 536 | proc = subprocess.Popen( |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 537 | [GIT, 'config', '--get-regexp', 'url.*.insteadof'], |
| 538 | cwd=local, |
| 539 | stdout=subprocess.PIPE) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 540 | for line in proc.stdout: |
| 541 | m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line) |
| 542 | if m: |
| 543 | new_url = m.group(1) |
| 544 | old_url = m.group(2) |
| 545 | if url.startswith(old_url): |
| 546 | url = new_url + url[len(old_url):] |
| 547 | break |
| 548 | proc.stdout.close() |
| 549 | proc.wait() |
| 550 | |
| 551 | if not url.startswith('http:') and not url.startswith('https:'): |
| 552 | return False |
| 553 | |
| 554 | dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b') |
| 555 | try: |
| 556 | try: |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 557 | r = urllib.request.urlopen(url) |
| 558 | except urllib.error.HTTPError as e: |
John Törnblom | d3ddcdb | 2015-08-12 20:12:51 +0200 | [diff] [blame] | 559 | if e.code in [401, 403, 404, 501]: |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 560 | return False |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 561 | _print('fatal: Cannot get %s' % url, file=sys.stderr) |
| 562 | _print('fatal: HTTP error %s' % e.code, file=sys.stderr) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 563 | raise CloneFailure() |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 564 | except urllib.error.URLError as e: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 565 | _print('fatal: Cannot get %s' % url, file=sys.stderr) |
| 566 | _print('fatal: error %s' % e.reason, file=sys.stderr) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 567 | raise CloneFailure() |
| 568 | try: |
| 569 | if not quiet: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 570 | _print('Get %s' % url, file=sys.stderr) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 571 | while True: |
| 572 | buf = r.read(8192) |
| 573 | if buf == '': |
| 574 | return True |
| 575 | dest.write(buf) |
| 576 | finally: |
| 577 | r.close() |
| 578 | finally: |
| 579 | dest.close() |
| 580 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 581 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 582 | def _ImportBundle(local): |
| 583 | path = os.path.join(local, '.git', 'clone.bundle') |
| 584 | try: |
| 585 | _Fetch(local, local, path, True) |
| 586 | finally: |
| 587 | os.remove(path) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 588 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 589 | |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 590 | def _Clone(url, local, quiet, clone_bundle): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 591 | """Clones a git repository to a new subdirectory of repodir |
| 592 | """ |
| 593 | try: |
| 594 | os.mkdir(local) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 595 | except OSError as e: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 596 | _print('fatal: cannot make %s directory: %s' % (local, e.strerror), |
| 597 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 598 | raise CloneFailure() |
| 599 | |
| 600 | cmd = [GIT, 'init', '--quiet'] |
| 601 | try: |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 602 | proc = subprocess.Popen(cmd, cwd=local) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 603 | except OSError as e: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 604 | _print(file=sys.stderr) |
| 605 | _print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
| 606 | _print('fatal: %s' % e, file=sys.stderr) |
| 607 | _print(file=sys.stderr) |
| 608 | _print('Please make sure %s is installed and in your path.' % GIT, |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 609 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 610 | raise CloneFailure() |
| 611 | if proc.wait() != 0: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 612 | _print('fatal: could not create %s' % local, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 613 | raise CloneFailure() |
| 614 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 615 | _InitHttp() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 616 | _SetConfig(local, 'remote.origin.url', url) |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 617 | _SetConfig(local, |
| 618 | 'remote.origin.fetch', |
| 619 | '+refs/heads/*:refs/remotes/origin/*') |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 620 | if clone_bundle and _DownloadBundle(url, local, quiet): |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 621 | _ImportBundle(local) |
Dan Willemsen | fee390e | 2015-09-02 12:36:30 -0700 | [diff] [blame] | 622 | _Fetch(url, local, 'origin', quiet) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 623 | |
| 624 | |
| 625 | def _Verify(cwd, branch, quiet): |
| 626 | """Verify the branch has been signed by a tag. |
| 627 | """ |
| 628 | cmd = [GIT, 'describe', 'origin/%s' % branch] |
| 629 | proc = subprocess.Popen(cmd, |
| 630 | stdout=subprocess.PIPE, |
| 631 | stderr=subprocess.PIPE, |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 632 | cwd=cwd) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 633 | cur = proc.stdout.read().strip() |
| 634 | proc.stdout.close() |
| 635 | |
| 636 | proc.stderr.read() |
| 637 | proc.stderr.close() |
| 638 | |
| 639 | if proc.wait() != 0 or not cur: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 640 | _print(file=sys.stderr) |
| 641 | _print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 642 | raise CloneFailure() |
| 643 | |
| 644 | m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur) |
| 645 | if m: |
| 646 | cur = m.group(1) |
| 647 | if not quiet: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 648 | _print(file=sys.stderr) |
| 649 | _print("info: Ignoring branch '%s'; using tagged release '%s'" |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 650 | % (branch, cur), file=sys.stderr) |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 651 | _print(file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 652 | |
Shawn O. Pearce | f18cb76 | 2010-12-07 11:41:05 -0800 | [diff] [blame] | 653 | env = os.environ.copy() |
Dāvis Mosāns | 631d0ec | 2016-07-16 21:11:11 +0300 | [diff] [blame] | 654 | try: |
| 655 | env['GNUPGHOME'] = gpg_dir |
| 656 | except UnicodeEncodeError: |
| 657 | env['GNUPGHOME'] = gpg_dir.encode() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 658 | |
| 659 | cmd = [GIT, 'tag', '-v', cur] |
| 660 | proc = subprocess.Popen(cmd, |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 661 | stdout=subprocess.PIPE, |
| 662 | stderr=subprocess.PIPE, |
| 663 | cwd=cwd, |
| 664 | env=env) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 665 | out = proc.stdout.read() |
| 666 | proc.stdout.close() |
| 667 | |
| 668 | err = proc.stderr.read() |
| 669 | proc.stderr.close() |
| 670 | |
| 671 | if proc.wait() != 0: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 672 | _print(file=sys.stderr) |
| 673 | _print(out, file=sys.stderr) |
| 674 | _print(err, file=sys.stderr) |
| 675 | _print(file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 676 | raise CloneFailure() |
| 677 | return '%s^0' % cur |
| 678 | |
| 679 | |
| 680 | def _Checkout(cwd, branch, rev, quiet): |
| 681 | """Checkout an upstream branch into the repository and track it. |
| 682 | """ |
| 683 | cmd = [GIT, 'update-ref', 'refs/heads/default', rev] |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 684 | if subprocess.Popen(cmd, cwd=cwd).wait() != 0: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 685 | raise CloneFailure() |
| 686 | |
| 687 | _SetConfig(cwd, 'branch.default.remote', 'origin') |
| 688 | _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch) |
| 689 | |
| 690 | cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default'] |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 691 | if subprocess.Popen(cmd, cwd=cwd).wait() != 0: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 692 | raise CloneFailure() |
| 693 | |
| 694 | cmd = [GIT, 'read-tree', '--reset', '-u'] |
| 695 | if not quiet: |
| 696 | cmd.append('-v') |
| 697 | cmd.append('HEAD') |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 698 | if subprocess.Popen(cmd, cwd=cwd).wait() != 0: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 699 | raise CloneFailure() |
| 700 | |
| 701 | |
| 702 | def _FindRepo(): |
| 703 | """Look for a repo installation, starting at the current directory. |
| 704 | """ |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 705 | curdir = os.getcwd() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 706 | repo = None |
| 707 | |
Anthony Newnam | df14a70 | 2011-01-09 17:31:57 -0800 | [diff] [blame] | 708 | olddir = None |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 709 | while curdir != '/' \ |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 710 | and curdir != olddir \ |
| 711 | and not repo: |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 712 | repo = os.path.join(curdir, repodir, REPO_MAIN) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 713 | if not os.path.isfile(repo): |
| 714 | repo = None |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 715 | olddir = curdir |
| 716 | curdir = os.path.dirname(curdir) |
| 717 | return (repo, os.path.join(curdir, repodir)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 718 | |
| 719 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 720 | class _Options(object): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 721 | help = False |
| 722 | |
| 723 | |
| 724 | def _ParseArguments(args): |
| 725 | cmd = None |
| 726 | opt = _Options() |
| 727 | arg = [] |
| 728 | |
Sarah Owens | a6053d5 | 2012-11-01 13:36:50 -0700 | [diff] [blame] | 729 | for i in range(len(args)): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 730 | a = args[i] |
| 731 | if a == '-h' or a == '--help': |
| 732 | opt.help = True |
| 733 | |
| 734 | elif not a.startswith('-'): |
| 735 | cmd = a |
| 736 | arg = args[i + 1:] |
| 737 | break |
| 738 | return cmd, opt, arg |
| 739 | |
| 740 | |
| 741 | def _Usage(): |
Dan Willemsen | 9ff2ece | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 742 | gitc_usage = "" |
| 743 | if get_gitc_manifest_dir(): |
| 744 | gitc_usage = " gitc-init Initialize a GITC Client.\n" |
| 745 | |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 746 | _print( |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 747 | """usage: repo COMMAND [ARGS] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 748 | |
| 749 | repo is not yet installed. Use "repo init" to install it here. |
| 750 | |
| 751 | The most commonly used repo commands are: |
| 752 | |
| 753 | init Install repo in the current working directory |
Dan Willemsen | 9ff2ece | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 754 | """ + gitc_usage + |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 755 | """ help Display detailed help on a command |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 756 | |
| 757 | For access to the full online help, install repo ("repo init"). |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 758 | """, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 759 | sys.exit(1) |
| 760 | |
| 761 | |
| 762 | def _Help(args): |
| 763 | if args: |
| 764 | if args[0] == 'init': |
| 765 | init_optparse.print_help() |
Trond Norbye | d3fd537 | 2011-01-03 11:35:15 +0100 | [diff] [blame] | 766 | sys.exit(0) |
Dan Willemsen | 9ff2ece | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 767 | elif args[0] == 'gitc-init': |
| 768 | _GitcInitOptions(init_optparse) |
| 769 | init_optparse.print_help() |
| 770 | sys.exit(0) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 771 | else: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 772 | _print("error: '%s' is not a bootstrap command.\n" |
| 773 | ' For access to online help, install repo ("repo init").' |
| 774 | % args[0], file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 775 | else: |
| 776 | _Usage() |
| 777 | sys.exit(1) |
| 778 | |
| 779 | |
| 780 | def _NotInstalled(): |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 781 | _print('error: repo is not installed. Use "repo init" to install it here.', |
| 782 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 783 | sys.exit(1) |
| 784 | |
| 785 | |
| 786 | def _NoCommands(cmd): |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 787 | _print("""error: command '%s' requires repo to be installed first. |
| 788 | Use "repo init" to install it here.""" % cmd, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 789 | sys.exit(1) |
| 790 | |
| 791 | |
| 792 | def _RunSelf(wrapper_path): |
| 793 | my_dir = os.path.dirname(wrapper_path) |
| 794 | my_main = os.path.join(my_dir, 'main.py') |
| 795 | my_git = os.path.join(my_dir, '.git') |
| 796 | |
| 797 | if os.path.isfile(my_main) and os.path.isdir(my_git): |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 798 | for name in ['git_config.py', |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 799 | 'project.py', |
| 800 | 'subcmds']: |
| 801 | if not os.path.exists(os.path.join(my_dir, name)): |
| 802 | return None, None |
| 803 | return my_main, my_git |
| 804 | return None, None |
| 805 | |
| 806 | |
| 807 | def _SetDefaultsTo(gitdir): |
| 808 | global REPO_URL |
| 809 | global REPO_REV |
| 810 | |
| 811 | REPO_URL = gitdir |
| 812 | proc = subprocess.Popen([GIT, |
| 813 | '--git-dir=%s' % gitdir, |
| 814 | 'symbolic-ref', |
| 815 | 'HEAD'], |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 816 | stdout=subprocess.PIPE, |
| 817 | stderr=subprocess.PIPE) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 818 | REPO_REV = proc.stdout.read().strip() |
| 819 | proc.stdout.close() |
| 820 | |
| 821 | proc.stderr.read() |
| 822 | proc.stderr.close() |
| 823 | |
| 824 | if proc.wait() != 0: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 825 | _print('fatal: %s has no current branch' % gitdir, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 826 | sys.exit(1) |
| 827 | |
| 828 | |
| 829 | def main(orig_args): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 830 | cmd, opt, args = _ParseArguments(orig_args) |
| 831 | |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 832 | repo_main, rel_repo_dir = None, None |
| 833 | # Don't use the local repo copy, make sure to switch to the gitc client first. |
| 834 | if cmd != 'gitc-init': |
| 835 | repo_main, rel_repo_dir = _FindRepo() |
| 836 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 837 | wrapper_path = os.path.abspath(__file__) |
| 838 | my_main, my_git = _RunSelf(wrapper_path) |
| 839 | |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 840 | cwd = os.getcwd() |
Dan Willemsen | 2487cb7 | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 841 | if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()): |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 842 | _print('error: repo cannot be used in the GITC local manifest directory.' |
| 843 | '\nIf you want to work on this GITC client please rerun this ' |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 844 | 'command from the corresponding client under /gitc/', |
| 845 | file=sys.stderr) |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 846 | sys.exit(1) |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 847 | if not repo_main: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 848 | if opt.help: |
| 849 | _Usage() |
| 850 | if cmd == 'help': |
| 851 | _Help(args) |
| 852 | if not cmd: |
| 853 | _NotInstalled() |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 854 | if cmd == 'init' or cmd == 'gitc-init': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 855 | if my_git: |
| 856 | _SetDefaultsTo(my_git) |
| 857 | try: |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 858 | _Init(args, gitc_init=(cmd == 'gitc-init')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 859 | except CloneFailure: |
Sebastian Schuberth | 27226e7 | 2016-10-28 14:27:43 +0200 | [diff] [blame] | 860 | path = os.path.join(repodir, S_repo) |
| 861 | _print("fatal: cloning the git-repo repository failed, will remove " |
| 862 | "'%s' " % path, file=sys.stderr) |
| 863 | shutil.rmtree(path, ignore_errors=True) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 864 | sys.exit(1) |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 865 | repo_main, rel_repo_dir = _FindRepo() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 866 | else: |
| 867 | _NoCommands(cmd) |
| 868 | |
| 869 | if my_main: |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 870 | repo_main = my_main |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 871 | |
David Pursehouse | 685f080 | 2012-11-14 08:34:39 +0900 | [diff] [blame] | 872 | ver_str = '.'.join(map(str, VERSION)) |
anatoly techtonik | 3a2a59e | 2013-09-21 19:29:10 +0300 | [diff] [blame] | 873 | me = [sys.executable, repo_main, |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 874 | '--repo-dir=%s' % rel_repo_dir, |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 875 | '--wrapper-version=%s' % ver_str, |
| 876 | '--wrapper-path=%s' % wrapper_path, |
| 877 | '--'] |
| 878 | me.extend(orig_args) |
| 879 | me.extend(extra_args) |
| 880 | try: |
anatoly techtonik | 3a2a59e | 2013-09-21 19:29:10 +0300 | [diff] [blame] | 881 | os.execv(sys.executable, me) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 882 | except OSError as e: |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 883 | _print("fatal: unable to start %s" % repo_main, file=sys.stderr) |
| 884 | _print("fatal: %s" % e, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 885 | sys.exit(148) |
| 886 | |
| 887 | |
| 888 | if __name__ == '__main__': |
Anthony King | 6efdde9 | 2014-05-05 20:37:05 +0100 | [diff] [blame] | 889 | if ver[0] == 3: |
| 890 | _print('warning: Python 3 support is currently experimental. YMMV.\n' |
| 891 | 'Please use Python 2.6 - 2.7 instead.', |
| 892 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 893 | main(sys.argv[1:]) |