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