blob: fbb136537470f8ab4a5942c691375bd7ec37b1ac [file] [log] [blame]
Wink Saville02d79452009-04-10 13:01:24 -07001# Copyright (C) 2009 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import sys
16from command import Command
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070017from progress import Progress
Wink Saville02d79452009-04-10 13:01:24 -070018
David Pursehouse819827a2020-02-12 15:20:19 +090019
Wink Saville02d79452009-04-10 13:01:24 -070020class 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
Mike Frysingerae6cb082019-08-27 01:10:59 -040035 def ValidateOptions(self, opt, args):
Wink Saville02d79452009-04-10 13:01:24 -070036 if not args:
37 self.Usage()
38
Mike Frysingerae6cb082019-08-27 01:10:59 -040039 def Execute(self, opt, args):
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070040 nb = args[0]
41 err = []
Doug Anderson3ba5f952011-04-07 12:51:04 -070042 success = []
David Pursehouse5c6eeac2012-10-11 16:44:48 +090043 all_projects = self.GetProjects(args[1:])
Wink Saville02d79452009-04-10 13:01:24 -070044
David Pursehouse5c6eeac2012-10-11 16:44:48 +090045 pm = Progress('Checkout %s' % nb, len(all_projects))
46 for project in all_projects:
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070047 pm.update()
Doug Anderson3ba5f952011-04-07 12:51:04 -070048
49 status = project.CheckoutBranch(nb)
50 if status is not None:
51 if status:
52 success.append(project)
53 else:
54 err.append(project)
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070055 pm.end()
Wink Saville02d79452009-04-10 13:01:24 -070056
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070057 if err:
Doug Anderson3ba5f952011-04-07 12:51:04 -070058 for p in err:
Sarah Owenscecd1d82012-11-01 22:59:27 -070059 print("error: %s/: cannot checkout %s" % (p.relpath, nb),
60 file=sys.stderr)
Doug Anderson3ba5f952011-04-07 12:51:04 -070061 sys.exit(1)
62 elif not success:
Sarah Owenscecd1d82012-11-01 22:59:27 -070063 print('error: no project has branch %s' % nb, file=sys.stderr)
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070064 sys.exit(1)