diff options
author | Shawn O. Pearce <sop@google.com> | 2009-04-13 11:51:15 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-04-13 11:53:53 -0700 |
commit | e756c412e35b9ac1a126985d4d047dbd52f29277 (patch) | |
tree | e5ed4a87a8b078e44c5369fbdf08b8e1c05d1ef6 /subcmds | |
parent | b812a3623646adf38f30dd5cf7e92f1e704669a2 (diff) | |
download | git-repo-e756c412e35b9ac1a126985d4d047dbd52f29277.tar.gz |
Add 'repo selfupdate' to upgrade only repo
Users may want to upgrade only repo to the latest release, but
leave their working tree state alone and avoid 'repo sync'.
Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'subcmds')
-rw-r--r-- | subcmds/selfupdate.py | 59 | ||||
-rw-r--r-- | subcmds/sync.py | 39 |
2 files changed, 83 insertions, 15 deletions
diff --git a/subcmds/selfupdate.py b/subcmds/selfupdate.py new file mode 100644 index 00000000..de6904c4 --- /dev/null +++ b/subcmds/selfupdate.py | |||
@@ -0,0 +1,59 @@ | |||
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 | |||
16 | from optparse import SUPPRESS_HELP | ||
17 | import sys | ||
18 | |||
19 | from command import Command, MirrorSafeCommand | ||
20 | from subcmds.sync import _PostRepoUpgrade | ||
21 | from subcmds.sync import _PostRepoFetch | ||
22 | |||
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): | ||
38 | p.add_option('--no-repo-verify', | ||
39 | dest='no_repo_verify', action='store_true', | ||
40 | help='do not verify repo source code') | ||
41 | p.add_option('--repo-upgraded', | ||
42 | dest='repo_upgraded', action='store_true', | ||
43 | help=SUPPRESS_HELP) | ||
44 | |||
45 | def Execute(self, opt, args): | ||
46 | rp = self.manifest.repoProject | ||
47 | rp.PreSync() | ||
48 | |||
49 | if opt.repo_upgraded: | ||
50 | _PostRepoUpgrade(self.manifest) | ||
51 | |||
52 | else: | ||
53 | if not rp.Sync_NetworkHalf(): | ||
54 | print >>sys.stderr, "error: can't update repo" | ||
55 | sys.exit(1) | ||
56 | |||
57 | _PostRepoFetch(rp, | ||
58 | no_repo_verify = opt.no_repo_verify, | ||
59 | verbose = True) | ||
diff --git a/subcmds/sync.py b/subcmds/sync.py index 79ffcf51..f6eb2a08 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -20,6 +20,7 @@ import subprocess | |||
20 | import sys | 20 | import sys |
21 | 21 | ||
22 | from git_command import GIT | 22 | from git_command import GIT |
23 | from project import HEAD | ||
23 | from command import Command, MirrorSafeCommand | 24 | from command import Command, MirrorSafeCommand |
24 | from error import RepoChangedException, GitError | 25 | from error import RepoChangedException, GitError |
25 | from project import R_HEADS | 26 | from project import R_HEADS |
@@ -99,26 +100,13 @@ revision is temporarily needed. | |||
99 | mp.PreSync() | 100 | mp.PreSync() |
100 | 101 | ||
101 | if opt.repo_upgraded: | 102 | if opt.repo_upgraded: |
102 | for project in self.manifest.projects.values(): | 103 | _PostRepoUpgrade(self.manifest) |
103 | if project.Exists: | ||
104 | project.PostRepoUpgrade() | ||
105 | 104 | ||
106 | all = self.GetProjects(args, missing_ok=True) | 105 | all = self.GetProjects(args, missing_ok=True) |
107 | 106 | ||
108 | if not opt.local_only: | 107 | if not opt.local_only: |
109 | fetched = self._Fetch(rp, mp, *all) | 108 | fetched = self._Fetch(rp, mp, *all) |
110 | 109 | _PostRepoFetch(rp, opt.no_repo_verify) | |
111 | if rp.HasChanges: | ||
112 | print >>sys.stderr, 'info: A new version of repo is available' | ||
113 | print >>sys.stderr, '' | ||
114 | if opt.no_repo_verify or _VerifyTag(rp): | ||
115 | if not rp.Sync_LocalHalf(): | ||
116 | sys.exit(1) | ||
117 | print >>sys.stderr, 'info: Restarting repo with latest version' | ||
118 | raise RepoChangedException(['--repo-upgraded']) | ||
119 | else: | ||
120 | print >>sys.stderr, 'warning: Skipped upgrade to unverified version' | ||
121 | |||
122 | if opt.network_only: | 110 | if opt.network_only: |
123 | # bail out now; the rest touches the working tree | 111 | # bail out now; the rest touches the working tree |
124 | return | 112 | return |
@@ -144,6 +132,27 @@ revision is temporarily needed. | |||
144 | sys.exit(1) | 132 | sys.exit(1) |
145 | pm.end() | 133 | pm.end() |
146 | 134 | ||
135 | |||
136 | def _PostRepoUpgrade(manifest): | ||
137 | for project in manifest.projects.values(): | ||
138 | if project.Exists: | ||
139 | project.PostRepoUpgrade() | ||
140 | |||
141 | def _PostRepoFetch(rp, no_repo_verify=False, verbose=False): | ||
142 | if rp.HasChanges: | ||
143 | print >>sys.stderr, 'info: A new version of repo is available' | ||
144 | print >>sys.stderr, '' | ||
145 | if no_repo_verify or _VerifyTag(rp): | ||
146 | if not rp.Sync_LocalHalf(): | ||
147 | sys.exit(1) | ||
148 | print >>sys.stderr, 'info: Restarting repo with latest version' | ||
149 | raise RepoChangedException(['--repo-upgraded']) | ||
150 | else: | ||
151 | print >>sys.stderr, 'warning: Skipped upgrade to unverified version' | ||
152 | else: | ||
153 | if verbose: | ||
154 | print >>sys.stderr, 'repo version %s is current' % rp.work_git.describe(HEAD) | ||
155 | |||
147 | def _VerifyTag(project): | 156 | def _VerifyTag(project): |
148 | gpg_dir = os.path.expanduser('~/.repoconfig/gnupg') | 157 | gpg_dir = os.path.expanduser('~/.repoconfig/gnupg') |
149 | if not os.path.exists(gpg_dir): | 158 | if not os.path.exists(gpg_dir): |