blob: d12e08d028b9f59292a4d8d4e3858c25ea9e0f23 [file] [log] [blame]
Shawn O. Pearcee756c412009-04-13 11:51:15 -07001#
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 Owenscecd1d82012-11-01 22:59:27 -070016from __future__ import print_function
Shawn O. Pearcee756c412009-04-13 11:51:15 -070017from optparse import SUPPRESS_HELP
18import sys
19
20from command import Command, MirrorSafeCommand
21from subcmds.sync import _PostRepoUpgrade
22from subcmds.sync import _PostRepoFetch
23
24class Selfupdate(Command, MirrorSafeCommand):
25 common = False
26 helpSummary = "Update repo to the latest version"
27 helpUsage = """
28%prog
29"""
30 helpDescription = """
31The '%prog' command upgrades repo to the latest version, if a
32newer version is available.
33
34Normally this is done automatically by 'repo sync' and does not
35need to be performed by an end-user.
36"""
37
38 def _Options(self, p):
Shawn O. Pearcefd89b672009-04-18 11:28:57 -070039 g = p.add_option_group('repo Version options')
40 g.add_option('--no-repo-verify',
Shawn O. Pearcee756c412009-04-13 11:51:15 -070041 dest='no_repo_verify', action='store_true',
42 help='do not verify repo source code')
Shawn O. Pearcefd89b672009-04-18 11:28:57 -070043 g.add_option('--repo-upgraded',
Shawn O. Pearcee756c412009-04-13 11:51:15 -070044 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 Owenscecd1d82012-11-01 22:59:27 -070056 print("error: can't update repo", file=sys.stderr)
Shawn O. Pearcee756c412009-04-13 11:51:15 -070057 sys.exit(1)
58
Shawn O. Pearce0d2b61f2009-07-03 15:22:49 -070059 rp.bare_git.gc('--auto')
Shawn O. Pearcee756c412009-04-13 11:51:15 -070060 _PostRepoFetch(rp,
61 no_repo_verify = opt.no_repo_verify,
62 verbose = True)