Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 1 | # Copyright (C) 2009 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 | from optparse import SUPPRESS_HELP |
| 16 | import sys |
| 17 | |
| 18 | from command import Command, MirrorSafeCommand |
| 19 | from subcmds.sync import _PostRepoUpgrade |
| 20 | from subcmds.sync import _PostRepoFetch |
| 21 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 22 | |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 23 | class Selfupdate(Command, MirrorSafeCommand): |
| 24 | common = False |
| 25 | helpSummary = "Update repo to the latest version" |
| 26 | helpUsage = """ |
| 27 | %prog |
| 28 | """ |
| 29 | helpDescription = """ |
| 30 | The '%prog' command upgrades repo to the latest version, if a |
| 31 | newer version is available. |
| 32 | |
| 33 | Normally this is done automatically by 'repo sync' and does not |
| 34 | need to be performed by an end-user. |
| 35 | """ |
| 36 | |
| 37 | def _Options(self, p): |
Shawn O. Pearce | fd89b67 | 2009-04-18 11:28:57 -0700 | [diff] [blame] | 38 | g = p.add_option_group('repo Version options') |
| 39 | g.add_option('--no-repo-verify', |
Mike Frysinger | c58ec4d | 2020-02-17 14:36:08 -0500 | [diff] [blame] | 40 | dest='repo_verify', default=True, action='store_false', |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 41 | help='do not verify repo source code') |
Shawn O. Pearce | fd89b67 | 2009-04-18 11:28:57 -0700 | [diff] [blame] | 42 | g.add_option('--repo-upgraded', |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 43 | dest='repo_upgraded', action='store_true', |
| 44 | help=SUPPRESS_HELP) |
| 45 | |
| 46 | def Execute(self, opt, args): |
| 47 | rp = self.manifest.repoProject |
| 48 | rp.PreSync() |
| 49 | |
| 50 | if opt.repo_upgraded: |
| 51 | _PostRepoUpgrade(self.manifest) |
| 52 | |
| 53 | else: |
| 54 | if not rp.Sync_NetworkHalf(): |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 55 | print("error: can't update repo", file=sys.stderr) |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 56 | sys.exit(1) |
| 57 | |
Shawn O. Pearce | 0d2b61f | 2009-07-03 15:22:49 -0700 | [diff] [blame] | 58 | rp.bare_git.gc('--auto') |
Shawn O. Pearce | e756c41 | 2009-04-13 11:51:15 -0700 | [diff] [blame] | 59 | _PostRepoFetch(rp, |
Mike Frysinger | c58ec4d | 2020-02-17 14:36:08 -0500 | [diff] [blame] | 60 | repo_verify=opt.repo_verify, |
David Pursehouse | e5913ae | 2020-02-12 13:56:59 +0900 | [diff] [blame] | 61 | verbose=True) |