blob: bf6256aba0bcb0d97ae33bf89352266432fc0ca1 [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
David Pursehouse819827a2020-02-12 15:20:19 +090025
Shawn O. Pearcee756c412009-04-13 11:51:15 -070026class Selfupdate(Command, MirrorSafeCommand):
27 common = False
28 helpSummary = "Update repo to the latest version"
29 helpUsage = """
30%prog
31"""
32 helpDescription = """
33The '%prog' command upgrades repo to the latest version, if a
34newer version is available.
35
36Normally this is done automatically by 'repo sync' and does not
37need to be performed by an end-user.
38"""
39
40 def _Options(self, p):
Shawn O. Pearcefd89b672009-04-18 11:28:57 -070041 g = p.add_option_group('repo Version options')
42 g.add_option('--no-repo-verify',
Mike Frysingerc58ec4d2020-02-17 14:36:08 -050043 dest='repo_verify', default=True, action='store_false',
Shawn O. Pearcee756c412009-04-13 11:51:15 -070044 help='do not verify repo source code')
Shawn O. Pearcefd89b672009-04-18 11:28:57 -070045 g.add_option('--repo-upgraded',
Shawn O. Pearcee756c412009-04-13 11:51:15 -070046 dest='repo_upgraded', action='store_true',
47 help=SUPPRESS_HELP)
48
49 def Execute(self, opt, args):
50 rp = self.manifest.repoProject
51 rp.PreSync()
52
53 if opt.repo_upgraded:
54 _PostRepoUpgrade(self.manifest)
55
56 else:
57 if not rp.Sync_NetworkHalf():
Sarah Owenscecd1d82012-11-01 22:59:27 -070058 print("error: can't update repo", file=sys.stderr)
Shawn O. Pearcee756c412009-04-13 11:51:15 -070059 sys.exit(1)
60
Shawn O. Pearce0d2b61f2009-07-03 15:22:49 -070061 rp.bare_git.gc('--auto')
Shawn O. Pearcee756c412009-04-13 11:51:15 -070062 _PostRepoFetch(rp,
Mike Frysingerc58ec4d2020-02-17 14:36:08 -050063 repo_verify=opt.repo_verify,
David Pursehousee5913ae2020-02-12 13:56:59 +090064 verbose=True)