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