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 |
| 16 | import sys |
| 17 | |
| 18 | from color import Coloring |
Mike Frysinger | 6447733 | 2023-08-21 21:20:32 -0400 | [diff] [blame] | 19 | from command import InteractiveCommand |
| 20 | from command import MirrorSafeCommand |
Jason Chang | f9aacd4 | 2023-08-03 14:38:00 -0700 | [diff] [blame] | 21 | from error import RepoUnhandledExceptionError |
Mike Frysinger | 6447733 | 2023-08-21 21:20:32 -0400 | [diff] [blame] | 22 | from error import UpdateManifestError |
| 23 | from git_command import git_require |
| 24 | from git_command import MIN_GIT_VERSION_HARD |
| 25 | from git_command import MIN_GIT_VERSION_SOFT |
Aravind Vasudevan | c993c50 | 2023-09-14 08:46:44 +0000 | [diff] [blame] | 26 | from repo_logging import RepoLogger |
Mike Frysinger | 6447733 | 2023-08-21 21:20:32 -0400 | [diff] [blame] | 27 | from wrapper import Wrapper |
| 28 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 29 | |
Aravind Vasudevan | c993c50 | 2023-09-14 08:46:44 +0000 | [diff] [blame] | 30 | logger = RepoLogger(__file__) |
| 31 | |
Jason Chang | 1783332 | 2023-05-23 13:06:55 -0700 | [diff] [blame] | 32 | _REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW") |
| 33 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 34 | |
Shawn O. Pearce | c95583b | 2009-03-03 17:47:06 -0800 | [diff] [blame] | 35 | class Init(InteractiveCommand, MirrorSafeCommand): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 36 | COMMON = True |
| 37 | MULTI_MANIFEST_SUPPORT = True |
| 38 | helpSummary = "Initialize a repo client checkout in the current directory" |
| 39 | helpUsage = """ |
Mike Frysinger | 401c6f0 | 2021-02-18 15:20:15 -0500 | [diff] [blame] | 40 | %prog [options] [manifest url] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 41 | """ |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 42 | helpDescription = """ |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 43 | The '%prog' command is run once to install and initialize repo. |
| 44 | The latest repo source code and manifest collection is downloaded |
| 45 | from the server and is installed in the .repo/ directory in the |
| 46 | current working directory. |
| 47 | |
Mike Frysinger | 401c6f0 | 2021-02-18 15:20:15 -0500 | [diff] [blame] | 48 | When creating a new checkout, the manifest URL is the only required setting. |
| 49 | It may be specified using the --manifest-url option, or as the first optional |
| 50 | argument. |
| 51 | |
Shawn O. Pearce | 77bb4af | 2009-04-18 11:33:32 -0700 | [diff] [blame] | 52 | The optional -b argument can be used to select the manifest branch |
Mike Frysinger | 50a81de | 2020-09-06 15:51:21 -0400 | [diff] [blame] | 53 | 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] | 54 | branch is used. This is equivalent to using -b HEAD. |
Shawn O. Pearce | 77bb4af | 2009-04-18 11:33:32 -0700 | [diff] [blame] | 55 | |
| 56 | The optional -m argument can be used to specify an alternate manifest |
| 57 | to be used. If no manifest is specified, the manifest default.xml |
| 58 | will be used. |
| 59 | |
Jack Neus | c474c9c | 2021-07-26 23:08:54 +0000 | [diff] [blame] | 60 | If the --standalone-manifest argument is set, the manifest will be downloaded |
| 61 | directly from the specified --manifest-url as a static file (rather than |
| 62 | setting up a manifest git checkout). With --standalone-manifest, the manifest |
| 63 | will be fully static and will not be re-downloaded during subsesquent |
| 64 | `repo init` and `repo sync` calls. |
| 65 | |
Shawn O. Pearce | 8844338 | 2010-10-08 10:02:09 +0200 | [diff] [blame] | 66 | The --reference option can be used to point to a directory that |
| 67 | has the content of a --mirror sync. This will make the working |
| 68 | directory use as much data as possible from the local reference |
| 69 | directory when fetching from the server. This will make the sync |
| 70 | go a lot faster by reducing data traffic on the network. |
| 71 | |
Nikolai Merinov | 09f0abb | 2018-10-19 15:07:05 +0500 | [diff] [blame] | 72 | The --dissociate option can be used to borrow the objects from |
| 73 | the directory specified with the --reference option only to reduce |
| 74 | network transfer, and stop borrowing from them after a first clone |
| 75 | is made by making necessary local copies of borrowed objects. |
| 76 | |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 77 | The --no-clone-bundle option disables any attempt to use |
| 78 | $URL/clone.bundle to bootstrap a new Git repository from a |
| 79 | resumeable bundle file on a content delivery network. This |
| 80 | may be necessary if there are problems with the local Python |
| 81 | HTTP client or proxy configuration, but the Git binary works. |
Shawn O. Pearce | 8844338 | 2010-10-08 10:02:09 +0200 | [diff] [blame] | 82 | |
Mike Frysinger | b8f7bb0 | 2018-10-10 01:05:11 -0400 | [diff] [blame] | 83 | # Switching Manifest Branches |
Shawn O. Pearce | 77bb4af | 2009-04-18 11:33:32 -0700 | [diff] [blame] | 84 | |
| 85 | To switch to another manifest branch, `repo init -b otherbranch` |
| 86 | may be used in an existing client. However, as this only updates the |
| 87 | manifest, a subsequent `repo sync` (or `repo sync -d`) is necessary |
| 88 | to update the working directory files. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 89 | """ |
| 90 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 91 | def _CommonOptions(self, p): |
| 92 | """Disable due to re-use of Wrapper().""" |
Mike Frysinger | 9180a07 | 2021-04-13 14:57:40 -0400 | [diff] [blame] | 93 | |
Jason Chang | 8914b1f | 2023-05-26 12:44:50 -0700 | [diff] [blame] | 94 | def _Options(self, p): |
| 95 | Wrapper().InitParser(p) |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 96 | m = p.add_option_group("Multi-manifest") |
| 97 | m.add_option( |
| 98 | "--outer-manifest", |
| 99 | action="store_true", |
| 100 | default=True, |
| 101 | help="operate starting at the outermost manifest", |
| 102 | ) |
| 103 | m.add_option( |
| 104 | "--no-outer-manifest", |
| 105 | dest="outer_manifest", |
| 106 | action="store_false", |
| 107 | help="do not operate on outer manifests", |
| 108 | ) |
| 109 | m.add_option( |
| 110 | "--this-manifest-only", |
| 111 | action="store_true", |
| 112 | default=None, |
| 113 | help="only operate on this (sub)manifest", |
| 114 | ) |
| 115 | m.add_option( |
| 116 | "--no-this-manifest-only", |
| 117 | "--all-manifests", |
| 118 | dest="this_manifest_only", |
| 119 | action="store_false", |
| 120 | help="operate on this manifest and its submanifests", |
| 121 | ) |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 122 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 123 | def _RegisteredEnvironmentOptions(self): |
| 124 | return { |
| 125 | "REPO_MANIFEST_URL": "manifest_url", |
| 126 | "REPO_MIRROR_LOCATION": "reference", |
| 127 | } |
David Pursehouse | 3f5ea0b | 2012-11-17 03:13:09 +0900 | [diff] [blame] | 128 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 129 | def _SyncManifest(self, opt): |
| 130 | """Call manifestProject.Sync with arguments from opt. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 131 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 132 | Args: |
| 133 | opt: options from optparse. |
| 134 | """ |
| 135 | # Normally this value is set when instantiating the project, but the |
| 136 | # manifest project is special and is created when instantiating the |
| 137 | # manifest which happens before we parse options. |
| 138 | self.manifest.manifestProject.clone_depth = opt.manifest_depth |
Jason Chang | 1783332 | 2023-05-23 13:06:55 -0700 | [diff] [blame] | 139 | clone_filter_for_depth = ( |
| 140 | "blob:none" if (_REPO_ALLOW_SHALLOW == "0") else None |
| 141 | ) |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 142 | if not self.manifest.manifestProject.Sync( |
| 143 | manifest_url=opt.manifest_url, |
| 144 | manifest_branch=opt.manifest_branch, |
| 145 | standalone_manifest=opt.standalone_manifest, |
| 146 | groups=opt.groups, |
| 147 | platform=opt.platform, |
| 148 | mirror=opt.mirror, |
| 149 | dissociate=opt.dissociate, |
| 150 | reference=opt.reference, |
| 151 | worktree=opt.worktree, |
| 152 | submodules=opt.submodules, |
| 153 | archive=opt.archive, |
| 154 | partial_clone=opt.partial_clone, |
| 155 | clone_filter=opt.clone_filter, |
| 156 | partial_clone_exclude=opt.partial_clone_exclude, |
Jason Chang | 1783332 | 2023-05-23 13:06:55 -0700 | [diff] [blame] | 157 | clone_filter_for_depth=clone_filter_for_depth, |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 158 | clone_bundle=opt.clone_bundle, |
| 159 | git_lfs=opt.git_lfs, |
| 160 | use_superproject=opt.use_superproject, |
| 161 | verbose=opt.verbose, |
| 162 | current_branch_only=opt.current_branch_only, |
| 163 | tags=opt.tags, |
| 164 | depth=opt.depth, |
| 165 | git_event_log=self.git_event_log, |
| 166 | manifest_name=opt.manifest_name, |
| 167 | ): |
Jason Chang | f9aacd4 | 2023-08-03 14:38:00 -0700 | [diff] [blame] | 168 | manifest_name = opt.manifest_name |
| 169 | raise UpdateManifestError( |
| 170 | f"Unable to sync manifest {manifest_name}" |
| 171 | ) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 172 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 173 | def _Prompt(self, prompt, value): |
| 174 | print("%-10s [%s]: " % (prompt, value), end="", flush=True) |
| 175 | a = sys.stdin.readline().strip() |
| 176 | if a == "": |
| 177 | return value |
| 178 | return a |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 179 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 180 | def _ShouldConfigureUser(self, opt, existing_checkout): |
| 181 | gc = self.client.globalConfig |
| 182 | mp = self.manifest.manifestProject |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 183 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 184 | # If we don't have local settings, get from global. |
| 185 | if not mp.config.Has("user.name") or not mp.config.Has("user.email"): |
| 186 | if not gc.Has("user.name") or not gc.Has("user.email"): |
| 187 | return True |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 188 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 189 | mp.config.SetString("user.name", gc.GetString("user.name")) |
| 190 | mp.config.SetString("user.email", gc.GetString("user.email")) |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 191 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 192 | if not opt.quiet and not existing_checkout or opt.verbose: |
| 193 | print() |
| 194 | print( |
| 195 | "Your identity is: %s <%s>" |
| 196 | % ( |
| 197 | mp.config.GetString("user.name"), |
| 198 | mp.config.GetString("user.email"), |
| 199 | ) |
| 200 | ) |
| 201 | print( |
| 202 | "If you want to change this, please re-run 'repo init' with " |
| 203 | "--config-name" |
| 204 | ) |
| 205 | return False |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 206 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 207 | def _ConfigureUser(self, opt): |
| 208 | mp = self.manifest.manifestProject |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 209 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 210 | while True: |
| 211 | if not opt.quiet: |
| 212 | print() |
| 213 | name = self._Prompt("Your Name", mp.UserName) |
| 214 | email = self._Prompt("Your Email", mp.UserEmail) |
| 215 | |
| 216 | if not opt.quiet: |
| 217 | print() |
Jason R. Coombs | b32ccbb | 2023-09-29 11:04:49 -0400 | [diff] [blame] | 218 | print(f"Your identity is: {name} <{email}>") |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 219 | print("is this correct [y/N]? ", end="", flush=True) |
| 220 | a = sys.stdin.readline().strip().lower() |
| 221 | if a in ("yes", "y", "t", "true"): |
| 222 | break |
| 223 | |
| 224 | if name != mp.UserName: |
| 225 | mp.config.SetString("user.name", name) |
| 226 | if email != mp.UserEmail: |
| 227 | mp.config.SetString("user.email", email) |
| 228 | |
| 229 | def _HasColorSet(self, gc): |
| 230 | for n in ["ui", "diff", "status"]: |
| 231 | if gc.Has("color.%s" % n): |
| 232 | return True |
| 233 | return False |
| 234 | |
| 235 | def _ConfigureColor(self): |
| 236 | gc = self.client.globalConfig |
| 237 | if self._HasColorSet(gc): |
| 238 | return |
| 239 | |
| 240 | class _Test(Coloring): |
| 241 | def __init__(self): |
| 242 | Coloring.__init__(self, gc, "test color display") |
| 243 | self._on = True |
| 244 | |
| 245 | out = _Test() |
| 246 | |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 247 | print() |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 248 | print("Testing colorized output (for 'repo diff', 'repo status'):") |
Shawn O. Pearce | 37dbf2b | 2009-07-02 10:53:04 -0700 | [diff] [blame] | 249 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 250 | for c in ["black", "red", "green", "yellow", "blue", "magenta", "cyan"]: |
| 251 | out.write(" ") |
| 252 | out.printer(fg=c)(" %-6s ", c) |
| 253 | out.write(" ") |
| 254 | out.printer(fg="white", bg="black")(" %s " % "white") |
| 255 | out.nl() |
| 256 | |
| 257 | for c in ["bold", "dim", "ul", "reverse"]: |
| 258 | out.write(" ") |
| 259 | out.printer(fg="black", attr=c)(" %-6s ", c) |
| 260 | out.nl() |
| 261 | |
| 262 | print( |
| 263 | "Enable color display in this user account (y/N)? ", |
| 264 | end="", |
| 265 | flush=True, |
| 266 | ) |
| 267 | a = sys.stdin.readline().strip().lower() |
| 268 | if a in ("y", "yes", "t", "true", "on"): |
| 269 | gc.SetString("color.ui", "auto") |
| 270 | |
| 271 | def _DisplayResult(self): |
| 272 | if self.manifest.IsMirror: |
| 273 | init_type = "mirror " |
| 274 | else: |
| 275 | init_type = "" |
| 276 | |
Mike Frysinger | 0b88891 | 2020-02-21 22:48:40 -0500 | [diff] [blame] | 277 | print() |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 278 | print( |
| 279 | "repo %shas been initialized in %s" |
| 280 | % (init_type, self.manifest.topdir) |
| 281 | ) |
Shawn O. Pearce | 37dbf2b | 2009-07-02 10:53:04 -0700 | [diff] [blame] | 282 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 283 | current_dir = os.getcwd() |
| 284 | if current_dir != self.manifest.topdir: |
| 285 | print( |
| 286 | "If this is not the directory in which you want to initialize " |
| 287 | "repo, please run:" |
| 288 | ) |
| 289 | print(" rm -r %s" % os.path.join(self.manifest.topdir, ".repo")) |
| 290 | print("and try again.") |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 291 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 292 | def ValidateOptions(self, opt, args): |
| 293 | if opt.reference: |
| 294 | opt.reference = os.path.expanduser(opt.reference) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 295 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 296 | # Check this here, else manifest will be tagged "not new" and init won't |
| 297 | # be possible anymore without removing the .repo/manifests directory. |
| 298 | if opt.mirror: |
| 299 | if opt.archive: |
| 300 | self.OptionParser.error( |
| 301 | "--mirror and --archive cannot be used " "together." |
| 302 | ) |
| 303 | if opt.use_superproject is not None: |
| 304 | self.OptionParser.error( |
| 305 | "--mirror and --use-superproject cannot be " |
| 306 | "used together." |
| 307 | ) |
| 308 | if opt.archive and opt.use_superproject is not None: |
| 309 | self.OptionParser.error( |
| 310 | "--archive and --use-superproject cannot be used " "together." |
| 311 | ) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 312 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 313 | if opt.standalone_manifest and ( |
| 314 | opt.manifest_branch or opt.manifest_name != "default.xml" |
| 315 | ): |
| 316 | self.OptionParser.error( |
| 317 | "--manifest-branch and --manifest-name cannot" |
| 318 | " be used with --standalone-manifest." |
| 319 | ) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 320 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 321 | if args: |
| 322 | if opt.manifest_url: |
| 323 | self.OptionParser.error( |
| 324 | "--manifest-url option and URL argument both specified: " |
| 325 | "only use one to select the manifest URL." |
| 326 | ) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 327 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 328 | opt.manifest_url = args.pop(0) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 329 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 330 | if args: |
| 331 | self.OptionParser.error("too many arguments to init") |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 332 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 333 | def Execute(self, opt, args): |
| 334 | git_require(MIN_GIT_VERSION_HARD, fail=True) |
| 335 | if not git_require(MIN_GIT_VERSION_SOFT): |
Aravind Vasudevan | c993c50 | 2023-09-14 08:46:44 +0000 | [diff] [blame] | 336 | logger.warning( |
| 337 | "repo: warning: git-%s+ will soon be required; " |
| 338 | "please upgrade your version of git to maintain " |
| 339 | "support.", |
| 340 | ".".join(str(x) for x in MIN_GIT_VERSION_SOFT), |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 341 | ) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 342 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 343 | rp = self.manifest.repoProject |
Yang Zhenhui | 75cc353 | 2012-10-23 15:41:54 +0800 | [diff] [blame] | 344 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 345 | # Handle new --repo-url requests. |
| 346 | if opt.repo_url: |
| 347 | remote = rp.GetRemote("origin") |
| 348 | remote.url = opt.repo_url |
| 349 | remote.Save() |
Yang Zhenhui | 75cc353 | 2012-10-23 15:41:54 +0800 | [diff] [blame] | 350 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 351 | # Handle new --repo-rev requests. |
| 352 | if opt.repo_rev: |
| 353 | wrapper = Wrapper() |
| 354 | try: |
| 355 | remote_ref, rev = wrapper.check_repo_rev( |
Jason R. Coombs | 560a797 | 2023-11-01 10:35:30 -0400 | [diff] [blame] | 356 | rp.worktree, |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 357 | opt.repo_rev, |
| 358 | repo_verify=opt.repo_verify, |
| 359 | quiet=opt.quiet, |
| 360 | ) |
Jason Chang | f9aacd4 | 2023-08-03 14:38:00 -0700 | [diff] [blame] | 361 | except wrapper.CloneFailure as e: |
Josip Sokcevic | 131fc96 | 2023-05-12 17:00:46 -0700 | [diff] [blame] | 362 | err_msg = "fatal: double check your --repo-rev setting." |
Aravind Vasudevan | c993c50 | 2023-09-14 08:46:44 +0000 | [diff] [blame] | 363 | logger.error(err_msg) |
Josip Sokcevic | 131fc96 | 2023-05-12 17:00:46 -0700 | [diff] [blame] | 364 | self.git_event_log.ErrorEvent(err_msg) |
Jason Chang | f9aacd4 | 2023-08-03 14:38:00 -0700 | [diff] [blame] | 365 | raise RepoUnhandledExceptionError(e) |
| 366 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 367 | branch = rp.GetBranch("default") |
| 368 | branch.merge = remote_ref |
| 369 | rp.work_git.reset("--hard", rev) |
| 370 | branch.Save() |
Yang Zhenhui | 75cc353 | 2012-10-23 15:41:54 +0800 | [diff] [blame] | 371 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 372 | if opt.worktree: |
| 373 | # Older versions of git supported worktree, but had dangerous gc |
| 374 | # bugs. |
| 375 | git_require((2, 15, 0), fail=True, msg="git gc worktree corruption") |
Victor Boivie | 297e7c6 | 2012-10-05 14:50:05 +0200 | [diff] [blame] | 376 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 377 | # Provide a short notice that we're reinitializing an existing checkout. |
| 378 | # Sometimes developers might not realize that they're in one, or that |
| 379 | # repo doesn't do nested checkouts. |
| 380 | existing_checkout = self.manifest.manifestProject.Exists |
| 381 | if not opt.quiet and existing_checkout: |
| 382 | print( |
| 383 | "repo: reusing existing repo client checkout in", |
| 384 | self.manifest.topdir, |
| 385 | ) |
Mike Frysinger | ae6cb08 | 2019-08-27 01:10:59 -0400 | [diff] [blame] | 386 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 387 | self._SyncManifest(opt) |
Jack Neus | c474c9c | 2021-07-26 23:08:54 +0000 | [diff] [blame] | 388 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 389 | if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror: |
| 390 | if opt.config_name or self._ShouldConfigureUser( |
| 391 | opt, existing_checkout |
| 392 | ): |
| 393 | self._ConfigureUser(opt) |
| 394 | self._ConfigureColor() |
Mike Frysinger | 401c6f0 | 2021-02-18 15:20:15 -0500 | [diff] [blame] | 395 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 396 | if not opt.quiet: |
| 397 | self._DisplayResult() |