blob: bfbe99218ddbe8ee5608571d89703ef93a6f5def [file] [log] [blame]
Wink Saville02d79452009-04-10 13:01:24 -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
16import sys
17from command import Command
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070018from progress import Progress
Wink Saville02d79452009-04-10 13:01:24 -070019
20class Checkout(Command):
21 common = True
22 helpSummary = "Checkout a branch for development"
23 helpUsage = """
24%prog <branchname> [<project>...]
Shawn O. Pearced33f43a2009-04-13 12:11:31 -070025"""
26 helpDescription = """
27The '%prog' command checks out an existing branch that was previously
28created by 'repo start'.
Wink Saville02d79452009-04-10 13:01:24 -070029
Shawn O. Pearced33f43a2009-04-13 12:11:31 -070030The command is equivalent to:
Wink Saville02d79452009-04-10 13:01:24 -070031
Shawn O. Pearced33f43a2009-04-13 12:11:31 -070032 repo forall [<project>...] -c git checkout <branchname>
Wink Saville02d79452009-04-10 13:01:24 -070033"""
34
35 def Execute(self, opt, args):
36 if not args:
37 self.Usage()
38
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070039 nb = args[0]
40 err = []
Doug Anderson3ba5f952011-04-07 12:51:04 -070041 success = []
David Pursehouse5c6eeac2012-10-11 16:44:48 +090042 all_projects = self.GetProjects(args[1:])
Wink Saville02d79452009-04-10 13:01:24 -070043
David Pursehouse5c6eeac2012-10-11 16:44:48 +090044 pm = Progress('Checkout %s' % nb, len(all_projects))
45 for project in all_projects:
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070046 pm.update()
Doug Anderson3ba5f952011-04-07 12:51:04 -070047
48 status = project.CheckoutBranch(nb)
49 if status is not None:
50 if status:
51 success.append(project)
52 else:
53 err.append(project)
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070054 pm.end()
Wink Saville02d79452009-04-10 13:01:24 -070055
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070056 if err:
Doug Anderson3ba5f952011-04-07 12:51:04 -070057 for p in err:
58 print >>sys.stderr,\
59 "error: %s/: cannot checkout %s" \
60 % (p.relpath, nb)
61 sys.exit(1)
62 elif not success:
63 print >>sys.stderr, 'error: no project has branch %s' % nb
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070064 sys.exit(1)