Mike Frysinger | f601376 | 2019-06-13 02:30:51 -0400 | [diff] [blame] | 1 | # -*- coding:utf-8 -*- |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2009 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 17 | from __future__ import print_function |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 18 | from optparse import SUPPRESS_HELP |
| 19 | import sys |
| 20 | |
| 21 | from command import Command, MirrorSafeCommand |
| 22 | from subcmds.sync import _PostRepoUpgrade |
| 23 | from subcmds.sync import _PostRepoFetch |
| 24 | |
| 25 | class Selfupdate(Command, MirrorSafeCommand): |
| 26 | common = False |
| 27 | helpSummary = "Update repo to the latest version" |
| 28 | helpUsage = """ |
| 29 | %prog |
| 30 | """ |
| 31 | helpDescription = """ |
| 32 | The '%prog' command upgrades repo to the latest version, if a |
| 33 | newer version is available. |
| 34 | |
| 35 | Normally this is done automatically by 'repo sync' and does not |
| 36 | need to be performed by an end-user. |
| 37 | """ |
| 38 | |
| 39 | def _Options(self, p): |
Shawn O. Pearce | fd89b67 | 2009-04-18 11:28:57 -0700 | [diff] [blame] | 40 | g = p.add_option_group('repo Version options') |
| 41 | g.add_option('--no-repo-verify', |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 42 | dest='no_repo_verify', action='store_true', |
| 43 | help='do not verify repo source code') |
Shawn O. Pearce | fd89b67 | 2009-04-18 11:28:57 -0700 | [diff] [blame] | 44 | g.add_option('--repo-upgraded', |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 45 | dest='repo_upgraded', action='store_true', |
| 46 | help=SUPPRESS_HELP) |
| 47 | |
| 48 | def Execute(self, opt, args): |
| 49 | rp = self.manifest.repoProject |
| 50 | rp.PreSync() |
| 51 | |
| 52 | if opt.repo_upgraded: |
| 53 | _PostRepoUpgrade(self.manifest) |
| 54 | |
| 55 | else: |
| 56 | if not rp.Sync_NetworkHalf(): |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 57 | print("error: can't update repo", file=sys.stderr) |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 58 | sys.exit(1) |
| 59 | |
Shawn O. Pearce | 0d2b61f | 2009-07-03 15:22:49 -0700 | [diff] [blame] | 60 | rp.bare_git.gc('--auto') |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 61 | _PostRepoFetch(rp, |
David Pursehouse | e5913ae | 2020-02-12 13:56:59 +0900 | [diff] [blame] | 62 | no_repo_verify=opt.no_repo_verify, |
| 63 | verbose=True) |