blob: b157e2f1db09277d1d061da7a86ccd1df9b14647 [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
Shawn O. Pearcee756c412009-04-13 11:51:15 -07002#
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 Owenscecd1d82012-11-01 22:59:27 -070017from __future__ import print_function
Shawn O. Pearcee756c412009-04-13 11:51:15 -070018from optparse import SUPPRESS_HELP
19import sys
20
21from command import Command, MirrorSafeCommand
22from subcmds.sync import _PostRepoUpgrade
23from subcmds.sync import _PostRepoFetch
24
25class Selfupdate(Command, MirrorSafeCommand):
26 common = False
27 helpSummary = "Update repo to the latest version"
28 helpUsage = """
29%prog
30"""
31 helpDescription = """
32The '%prog' command upgrades repo to the latest version, if a
33newer version is available.
34
35Normally this is done automatically by 'repo sync' and does not
36need to be performed by an end-user.
37"""
38
39 def _Options(self, p):
Shawn O. Pearcefd89b672009-04-18 11:28:57 -070040 g = p.add_option_group('repo Version options')
41 g.add_option('--no-repo-verify',
Shawn O. Pearcee756c412009-04-13 11:51:15 -070042 dest='no_repo_verify', action='store_true',
43 help='do not verify repo source code')
Shawn O. Pearcefd89b672009-04-18 11:28:57 -070044 g.add_option('--repo-upgraded',
Shawn O. Pearcee756c412009-04-13 11:51:15 -070045 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 Owenscecd1d82012-11-01 22:59:27 -070057 print("error: can't update repo", file=sys.stderr)
Shawn O. Pearcee756c412009-04-13 11:51:15 -070058 sys.exit(1)
59
Shawn O. Pearce0d2b61f2009-07-03 15:22:49 -070060 rp.bare_git.gc('--auto')
Shawn O. Pearcee756c412009-04-13 11:51:15 -070061 _PostRepoFetch(rp,
David Pursehousee5913ae2020-02-12 13:56:59 +090062 no_repo_verify=opt.no_repo_verify,
63 verbose=True)