The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # Copyright (C) 2008 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import os |
Conley Owens | d21720d | 2012-04-16 11:02:21 -0700 | [diff] [blame] | 16 | import platform |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 17 | import re |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 18 | import sys |
Mike Frysinger | acf63b2 | 2019-06-13 02:24:21 -0400 | [diff] [blame] | 19 | import urllib.parse |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | |
| 21 | from color import Coloring |
Shawn O. Pearce | c95583b | 2009-03-03 17:47:06 -0800 | [diff] [blame] | 22 | from command import InteractiveCommand, MirrorSafeCommand |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 23 | from error import ManifestParseError |
Jonathan Nieder | 9371979 | 2015-03-17 11:29:58 -0700 | [diff] [blame] | 24 | from project import SyncBuffer |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 25 | from git_config import GitConfig |
Mike Frysinger | 82caef6 | 2020-02-11 18:51:08 -0500 | [diff] [blame] | 26 | from git_command import git_require, MIN_GIT_VERSION_SOFT, MIN_GIT_VERSION_HARD |
Mike Frysinger | 3599cc3 | 2020-02-29 02:53:41 -0500 | [diff] [blame] | 27 | from wrapper import Wrapper |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 28 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 29 | |
Shawn O. Pearce | c95583b | 2009-03-03 17:47:06 -0800 | [diff] [blame] | 30 | class Init(InteractiveCommand, MirrorSafeCommand): |
Mike Frysinger | 4f21054 | 2021-06-14 16:05:19 -0400 | [diff] [blame] | 31 | COMMON = True |
LaMont Jones | 409407a | 2022-04-05 21:21:56 +0000 | [diff] [blame] | 32 | MULTI_MANIFEST_SUPPORT = True |
Mike Frysinger | 401c6f0 | 2021-02-18 15:20:15 -0500 | [diff] [blame] | 33 | helpSummary = "Initialize a repo client checkout in the current directory" |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 34 | helpUsage = """ |
Mike Frysinger | 401c6f0 | 2021-02-18 15:20:15 -0500 | [diff] [blame] | 35 | %prog [options] [manifest url] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 36 | """ |
| 37 | helpDescription = """ |
| 38 | The '%prog' command is run once to install and initialize repo. |
| 39 | The latest repo source code and manifest collection is downloaded |
| 40 | from the server and is installed in the .repo/ directory in the |
| 41 | current working directory. |
| 42 | |
Mike Frysinger | 401c6f0 | 2021-02-18 15:20:15 -0500 | [diff] [blame] | 43 | When creating a new checkout, the manifest URL is the only required setting. |
| 44 | It may be specified using the --manifest-url option, or as the first optional |
| 45 | argument. |
| 46 | |
Shawn O. Pearce | 77bb4af | 2009-04-18 11:33:32 -0700 | [diff] [blame] | 47 | The optional -b argument can be used to select the manifest branch |
Mike Frysinger | 50a81de | 2020-09-06 15:51:21 -0400 | [diff] [blame] | 48 | to checkout and use. If no branch is specified, the remote's default |
Mike Frysinger | 23882b3 | 2021-02-23 15:43:07 -0500 | [diff] [blame] | 49 | branch is used. This is equivalent to using -b HEAD. |
Shawn O. Pearce | 77bb4af | 2009-04-18 11:33:32 -0700 | [diff] [blame] | 50 | |
| 51 | The optional -m argument can be used to specify an alternate manifest |
| 52 | to be used. If no manifest is specified, the manifest default.xml |
| 53 | will be used. |
| 54 | |
Jack Neus | c474c9c | 2021-07-26 23:08:54 +0000 | [diff] [blame] | 55 | If the --standalone-manifest argument is set, the manifest will be downloaded |
| 56 | directly from the specified --manifest-url as a static file (rather than |
| 57 | setting up a manifest git checkout). With --standalone-manifest, the manifest |
| 58 | will be fully static and will not be re-downloaded during subsesquent |
| 59 | `repo init` and `repo sync` calls. |
| 60 | |
Shawn O. Pearce | 8844338 | 2010-10-08 10:02:09 +0200 | [diff] [blame] | 61 | The --reference option can be used to point to a directory that |
| 62 | has the content of a --mirror sync. This will make the working |
| 63 | directory use as much data as possible from the local reference |
| 64 | directory when fetching from the server. This will make the sync |
| 65 | go a lot faster by reducing data traffic on the network. |
| 66 | |
Nikolai Merinov | 09f0abb | 2018-10-19 15:07:05 +0500 | [diff] [blame] | 67 | The --dissociate option can be used to borrow the objects from |
| 68 | the directory specified with the --reference option only to reduce |
| 69 | network transfer, and stop borrowing from them after a first clone |
| 70 | is made by making necessary local copies of borrowed objects. |
| 71 | |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 72 | The --no-clone-bundle option disables any attempt to use |
| 73 | $URL/clone.bundle to bootstrap a new Git repository from a |
| 74 | resumeable bundle file on a content delivery network. This |
| 75 | may be necessary if there are problems with the local Python |
| 76 | HTTP client or proxy configuration, but the Git binary works. |
Shawn O. Pearce | 8844338 | 2010-10-08 10:02:09 +0200 | [diff] [blame] | 77 | |
Mike Frysinger | b8f7bb0 | 2018-10-10 01:05:11 -0400 | [diff] [blame] | 78 | # Switching Manifest Branches |
Shawn O. Pearce | 77bb4af | 2009-04-18 11:33:32 -0700 | [diff] [blame] | 79 | |
| 80 | To switch to another manifest branch, `repo init -b otherbranch` |
| 81 | may be used in an existing client. However, as this only updates the |
| 82 | manifest, a subsequent `repo sync` (or `repo sync -d`) is necessary |
| 83 | to update the working directory files. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 84 | """ |
| 85 | |
Mike Frysinger | 9180a07 | 2021-04-13 14:57:40 -0400 | [diff] [blame] | 86 | def _CommonOptions(self, p): |
| 87 | """Disable due to re-use of Wrapper().""" |
| 88 | |
Mike Frysinger | 66098f7 | 2020-02-05 00:01:59 -0500 | [diff] [blame] | 89 | def _Options(self, p, gitc_init=False): |
Mike Frysinger | 9a734a3 | 2021-04-08 19:14:15 -0400 | [diff] [blame] | 90 | Wrapper().InitParser(p, gitc_init=gitc_init) |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 91 | m = p.add_option_group('Multi-manifest') |
LaMont Jones | bdcba7d | 2022-04-11 22:50:11 +0000 | [diff] [blame] | 92 | m.add_option('--outer-manifest', action='store_true', default=True, |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 93 | help='operate starting at the outermost manifest') |
| 94 | m.add_option('--no-outer-manifest', dest='outer_manifest', |
LaMont Jones | bdcba7d | 2022-04-11 22:50:11 +0000 | [diff] [blame] | 95 | action='store_false', help='do not operate on outer manifests') |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 96 | m.add_option('--this-manifest-only', action='store_true', default=None, |
| 97 | help='only operate on this (sub)manifest') |
| 98 | m.add_option('--no-this-manifest-only', '--all-manifests', |
| 99 | dest='this_manifest_only', action='store_false', |
| 100 | help='operate on this manifest and its submanifests') |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 101 | |
David Pursehouse | 3f5ea0b | 2012-11-17 03:13:09 +0900 | [diff] [blame] | 102 | def _RegisteredEnvironmentOptions(self): |
| 103 | return {'REPO_MANIFEST_URL': 'manifest_url', |
| 104 | 'REPO_MIRROR_LOCATION': 'reference'} |
| 105 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 106 | def _SyncManifest(self, opt): |
LaMont Jones | 9b03f15 | 2022-03-29 23:01:18 +0000 | [diff] [blame] | 107 | """Call manifestProject.Sync with arguments from opt. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 108 | |
LaMont Jones | 9b03f15 | 2022-03-29 23:01:18 +0000 | [diff] [blame] | 109 | Args: |
| 110 | opt: options from optparse. |
| 111 | """ |
| 112 | if not self.manifest.manifestProject.Sync( |
| 113 | manifest_url=opt.manifest_url, |
| 114 | manifest_branch=opt.manifest_branch, |
| 115 | standalone_manifest=opt.standalone_manifest, |
| 116 | groups=opt.groups, |
| 117 | platform=opt.platform, |
| 118 | mirror=opt.mirror, |
| 119 | dissociate=opt.dissociate, |
| 120 | reference=opt.reference, |
| 121 | worktree=opt.worktree, |
| 122 | submodules=opt.submodules, |
| 123 | archive=opt.archive, |
| 124 | partial_clone=opt.partial_clone, |
| 125 | clone_filter=opt.clone_filter, |
| 126 | partial_clone_exclude=opt.partial_clone_exclude, |
| 127 | clone_bundle=opt.clone_bundle, |
| 128 | git_lfs=opt.git_lfs, |
| 129 | use_superproject=opt.use_superproject, |
| 130 | verbose=opt.verbose, |
| 131 | current_branch_only=opt.current_branch_only, |
| 132 | tags=opt.tags, |
LaMont Jones | 409407a | 2022-04-05 21:21:56 +0000 | [diff] [blame] | 133 | depth=opt.depth, |
LaMont Jones | 55ee304 | 2022-04-06 17:10:21 +0000 | [diff] [blame] | 134 | git_event_log=self.git_event_log, |
LaMont Jones | 409407a | 2022-04-05 21:21:56 +0000 | [diff] [blame] | 135 | manifest_name=opt.manifest_name): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 136 | sys.exit(1) |
| 137 | |
Shawn O. Pearce | 37dbf2b | 2009-07-02 10:53:04 -0700 | [diff] [blame] | 138 | def _Prompt(self, prompt, value): |
Mike Frysinger | ab85fe7 | 2019-07-04 17:35:11 -0400 | [diff] [blame] | 139 | print('%-10s [%s]: ' % (prompt, value), end='') |
| 140 | # TODO: When we require Python 3, use flush=True w/print above. |
| 141 | sys.stdout.flush() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 142 | a = sys.stdin.readline().strip() |
Shawn O. Pearce | 37dbf2b | 2009-07-02 10:53:04 -0700 | [diff] [blame] | 143 | if a == '': |
| 144 | return value |
| 145 | return a |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 146 | |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 147 | def _ShouldConfigureUser(self, opt): |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 148 | gc = self.client.globalConfig |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 149 | mp = self.manifest.manifestProject |
| 150 | |
| 151 | # If we don't have local settings, get from global. |
| 152 | if not mp.config.Has('user.name') or not mp.config.Has('user.email'): |
| 153 | if not gc.Has('user.name') or not gc.Has('user.email'): |
| 154 | return True |
| 155 | |
| 156 | mp.config.SetString('user.name', gc.GetString('user.name')) |
| 157 | mp.config.SetString('user.email', gc.GetString('user.email')) |
| 158 | |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 159 | if not opt.quiet: |
| 160 | print() |
| 161 | print('Your identity is: %s <%s>' % (mp.config.GetString('user.name'), |
| 162 | mp.config.GetString('user.email'))) |
| 163 | print("If you want to change this, please re-run 'repo init' with --config-name") |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 164 | return False |
| 165 | |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 166 | def _ConfigureUser(self, opt): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 167 | mp = self.manifest.manifestProject |
| 168 | |
Shawn O. Pearce | 37dbf2b | 2009-07-02 10:53:04 -0700 | [diff] [blame] | 169 | while True: |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 170 | if not opt.quiet: |
| 171 | print() |
David Pursehouse | 54a4e60 | 2020-02-12 14:31:05 +0900 | [diff] [blame] | 172 | name = self._Prompt('Your Name', mp.UserName) |
Shawn O. Pearce | 37dbf2b | 2009-07-02 10:53:04 -0700 | [diff] [blame] | 173 | email = self._Prompt('Your Email', mp.UserEmail) |
| 174 | |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 175 | if not opt.quiet: |
| 176 | print() |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 177 | print('Your identity is: %s <%s>' % (name, email)) |
Mike Frysinger | ab85fe7 | 2019-07-04 17:35:11 -0400 | [diff] [blame] | 178 | print('is this correct [y/N]? ', end='') |
| 179 | # TODO: When we require Python 3, use flush=True w/print above. |
| 180 | sys.stdout.flush() |
David Pursehouse | fc24124 | 2012-11-14 09:19:39 +0900 | [diff] [blame] | 181 | a = sys.stdin.readline().strip().lower() |
Nico Sallembien | 6d7508b | 2010-04-01 11:03:53 -0700 | [diff] [blame] | 182 | if a in ('yes', 'y', 't', 'true'): |
Shawn O. Pearce | 37dbf2b | 2009-07-02 10:53:04 -0700 | [diff] [blame] | 183 | break |
| 184 | |
| 185 | if name != mp.UserName: |
| 186 | mp.config.SetString('user.name', name) |
| 187 | if email != mp.UserEmail: |
| 188 | mp.config.SetString('user.email', email) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 189 | |
| 190 | def _HasColorSet(self, gc): |
| 191 | for n in ['ui', 'diff', 'status']: |
| 192 | if gc.Has('color.%s' % n): |
| 193 | return True |
| 194 | return False |
| 195 | |
| 196 | def _ConfigureColor(self): |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 197 | gc = self.client.globalConfig |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 198 | if self._HasColorSet(gc): |
| 199 | return |
| 200 | |
| 201 | class _Test(Coloring): |
| 202 | def __init__(self): |
| 203 | Coloring.__init__(self, gc, 'test color display') |
| 204 | self._on = True |
| 205 | out = _Test() |
| 206 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 207 | print() |
| 208 | print("Testing colorized output (for 'repo diff', 'repo status'):") |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 209 | |
David Pursehouse | 8f62fb7 | 2012-11-14 12:09:38 +0900 | [diff] [blame] | 210 | for c in ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan']: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 211 | out.write(' ') |
| 212 | out.printer(fg=c)(' %-6s ', c) |
| 213 | out.write(' ') |
| 214 | out.printer(fg='white', bg='black')(' %s ' % 'white') |
| 215 | out.nl() |
| 216 | |
David Pursehouse | 8f62fb7 | 2012-11-14 12:09:38 +0900 | [diff] [blame] | 217 | for c in ['bold', 'dim', 'ul', 'reverse']: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 218 | out.write(' ') |
| 219 | out.printer(fg='black', attr=c)(' %-6s ', c) |
| 220 | out.nl() |
| 221 | |
Mike Frysinger | ab85fe7 | 2019-07-04 17:35:11 -0400 | [diff] [blame] | 222 | print('Enable color display in this user account (y/N)? ', end='') |
| 223 | # TODO: When we require Python 3, use flush=True w/print above. |
| 224 | sys.stdout.flush() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 225 | a = sys.stdin.readline().strip().lower() |
| 226 | if a in ('y', 'yes', 't', 'true', 'on'): |
| 227 | gc.SetString('color.ui', 'auto') |
| 228 | |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 229 | def _DisplayResult(self, opt): |
Yang Zhenhui | 75cc353 | 2012-10-23 15:41:54 +0800 | [diff] [blame] | 230 | if self.manifest.IsMirror: |
| 231 | init_type = 'mirror ' |
| 232 | else: |
| 233 | init_type = '' |
| 234 | |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 235 | if not opt.quiet: |
| 236 | print() |
| 237 | print('repo %shas been initialized in %s' % |
| 238 | (init_type, self.manifest.topdir)) |
Yang Zhenhui | 75cc353 | 2012-10-23 15:41:54 +0800 | [diff] [blame] | 239 | |
| 240 | current_dir = os.getcwd() |
| 241 | if current_dir != self.manifest.topdir: |
David Pursehouse | 3576596 | 2013-01-29 09:49:48 +0900 | [diff] [blame] | 242 | print('If this is not the directory in which you want to initialize ' |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 243 | 'repo, please run:') |
Mateus Azis | bddc964 | 2022-07-21 08:13:09 -0700 | [diff] [blame] | 244 | print(' rm -r %s' % os.path.join(self.manifest.topdir, '.repo')) |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 245 | print('and try again.') |
Yang Zhenhui | 75cc353 | 2012-10-23 15:41:54 +0800 | [diff] [blame] | 246 | |
Mike Frysinger | ae6cb08 | 2019-08-27 01:10:59 -0400 | [diff] [blame] | 247 | def ValidateOptions(self, opt, args): |
Victor Boivie | 297e7c6 | 2012-10-05 14:50:05 +0200 | [diff] [blame] | 248 | if opt.reference: |
Samuel Holland | baa0009 | 2018-01-22 10:57:29 -0600 | [diff] [blame] | 249 | opt.reference = os.path.expanduser(opt.reference) |
Victor Boivie | 297e7c6 | 2012-10-05 14:50:05 +0200 | [diff] [blame] | 250 | |
Julien Campergue | 335f5ef | 2013-10-16 11:02:35 +0200 | [diff] [blame] | 251 | # Check this here, else manifest will be tagged "not new" and init won't be |
| 252 | # possible anymore without removing the .repo/manifests directory. |
Raman Tenneti | 6bd89aa | 2021-11-16 11:48:09 -0800 | [diff] [blame] | 253 | if opt.mirror: |
| 254 | if opt.archive: |
| 255 | self.OptionParser.error('--mirror and --archive cannot be used ' |
| 256 | 'together.') |
| 257 | if opt.use_superproject is not None: |
| 258 | self.OptionParser.error('--mirror and --use-superproject cannot be ' |
| 259 | 'used together.') |
LaMont Jones | 5fa912b | 2022-04-14 14:41:13 +0000 | [diff] [blame] | 260 | if opt.archive and opt.use_superproject is not None: |
| 261 | self.OptionParser.error('--archive and --use-superproject cannot be used ' |
| 262 | 'together.') |
Mike Frysinger | ae6cb08 | 2019-08-27 01:10:59 -0400 | [diff] [blame] | 263 | |
Raman Tenneti | 4a478ed | 2021-11-17 18:38:24 -0800 | [diff] [blame] | 264 | if opt.standalone_manifest and (opt.manifest_branch or |
| 265 | opt.manifest_name != 'default.xml'): |
Jack Neus | c474c9c | 2021-07-26 23:08:54 +0000 | [diff] [blame] | 266 | self.OptionParser.error('--manifest-branch and --manifest-name cannot' |
| 267 | ' be used with --standalone-manifest.') |
| 268 | |
Mike Frysinger | 0578ebf | 2020-08-27 01:50:12 -0400 | [diff] [blame] | 269 | if args: |
Mike Frysinger | 401c6f0 | 2021-02-18 15:20:15 -0500 | [diff] [blame] | 270 | if opt.manifest_url: |
| 271 | self.OptionParser.error( |
| 272 | '--manifest-url option and URL argument both specified: only use ' |
| 273 | 'one to select the manifest URL.') |
| 274 | |
| 275 | opt.manifest_url = args.pop(0) |
| 276 | |
| 277 | if args: |
| 278 | self.OptionParser.error('too many arguments to init') |
Mike Frysinger | 0578ebf | 2020-08-27 01:50:12 -0400 | [diff] [blame] | 279 | |
Mike Frysinger | ae6cb08 | 2019-08-27 01:10:59 -0400 | [diff] [blame] | 280 | def Execute(self, opt, args): |
Mike Frysinger | 82caef6 | 2020-02-11 18:51:08 -0500 | [diff] [blame] | 281 | git_require(MIN_GIT_VERSION_HARD, fail=True) |
| 282 | if not git_require(MIN_GIT_VERSION_SOFT): |
| 283 | print('repo: warning: git-%s+ will soon be required; please upgrade your ' |
| 284 | 'version of git to maintain support.' |
| 285 | % ('.'.join(str(x) for x in MIN_GIT_VERSION_SOFT),), |
| 286 | file=sys.stderr) |
Julien Campergue | 335f5ef | 2013-10-16 11:02:35 +0200 | [diff] [blame] | 287 | |
Mike Frysinger | 7936ce8 | 2020-02-29 02:53:41 -0500 | [diff] [blame] | 288 | rp = self.manifest.repoProject |
| 289 | |
| 290 | # Handle new --repo-url requests. |
| 291 | if opt.repo_url: |
| 292 | remote = rp.GetRemote('origin') |
| 293 | remote.url = opt.repo_url |
| 294 | remote.Save() |
| 295 | |
Mike Frysinger | 3599cc3 | 2020-02-29 02:53:41 -0500 | [diff] [blame] | 296 | # Handle new --repo-rev requests. |
| 297 | if opt.repo_rev: |
| 298 | wrapper = Wrapper() |
Mike Frysinger | 4aa8584 | 2022-01-25 02:10:28 -0500 | [diff] [blame] | 299 | try: |
| 300 | remote_ref, rev = wrapper.check_repo_rev( |
| 301 | rp.gitdir, opt.repo_rev, repo_verify=opt.repo_verify, quiet=opt.quiet) |
| 302 | except wrapper.CloneFailure: |
| 303 | print('fatal: double check your --repo-rev setting.', file=sys.stderr) |
| 304 | sys.exit(1) |
Mike Frysinger | 3599cc3 | 2020-02-29 02:53:41 -0500 | [diff] [blame] | 305 | branch = rp.GetBranch('default') |
| 306 | branch.merge = remote_ref |
Mike Frysinger | 5e2f32f | 2020-12-05 22:57:19 -0500 | [diff] [blame] | 307 | rp.work_git.reset('--hard', rev) |
Mike Frysinger | 3599cc3 | 2020-02-29 02:53:41 -0500 | [diff] [blame] | 308 | branch.Save() |
| 309 | |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 310 | if opt.worktree: |
| 311 | # Older versions of git supported worktree, but had dangerous gc bugs. |
| 312 | git_require((2, 15, 0), fail=True, msg='git gc worktree corruption') |
| 313 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 314 | self._SyncManifest(opt) |
Raman Tenneti | 21dce3d | 2021-02-09 00:26:31 -0800 | [diff] [blame] | 315 | |
Shawn O. Pearce | 8630f39 | 2009-03-19 10:17:12 -0700 | [diff] [blame] | 316 | if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror: |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 317 | if opt.config_name or self._ShouldConfigureUser(opt): |
| 318 | self._ConfigureUser(opt) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 319 | self._ConfigureColor() |
| 320 | |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 321 | self._DisplayResult(opt) |