blob: efa31d266a8b3b8194252d5359b0457af9eaaed1 [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
Wink Saville02d79452009-04-10 13:01:24 -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
Wink Saville02d79452009-04-10 13:01:24 -070018import sys
19from command import Command
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070020from progress import Progress
Wink Saville02d79452009-04-10 13:01:24 -070021
David Pursehouse819827a2020-02-12 15:20:19 +090022
Wink Saville02d79452009-04-10 13:01:24 -070023class Checkout(Command):
24 common = True
25 helpSummary = "Checkout a branch for development"
26 helpUsage = """
27%prog <branchname> [<project>...]
Shawn O. Pearced33f43a2009-04-13 12:11:31 -070028"""
29 helpDescription = """
30The '%prog' command checks out an existing branch that was previously
31created by 'repo start'.
Wink Saville02d79452009-04-10 13:01:24 -070032
Shawn O. Pearced33f43a2009-04-13 12:11:31 -070033The command is equivalent to:
Wink Saville02d79452009-04-10 13:01:24 -070034
Shawn O. Pearced33f43a2009-04-13 12:11:31 -070035 repo forall [<project>...] -c git checkout <branchname>
Wink Saville02d79452009-04-10 13:01:24 -070036"""
37
Mike Frysingerae6cb082019-08-27 01:10:59 -040038 def ValidateOptions(self, opt, args):
Wink Saville02d79452009-04-10 13:01:24 -070039 if not args:
40 self.Usage()
41
Mike Frysingerae6cb082019-08-27 01:10:59 -040042 def Execute(self, opt, args):
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070043 nb = args[0]
44 err = []
Doug Anderson3ba5f952011-04-07 12:51:04 -070045 success = []
David Pursehouse5c6eeac2012-10-11 16:44:48 +090046 all_projects = self.GetProjects(args[1:])
Wink Saville02d79452009-04-10 13:01:24 -070047
David Pursehouse5c6eeac2012-10-11 16:44:48 +090048 pm = Progress('Checkout %s' % nb, len(all_projects))
49 for project in all_projects:
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070050 pm.update()
Doug Anderson3ba5f952011-04-07 12:51:04 -070051
52 status = project.CheckoutBranch(nb)
53 if status is not None:
54 if status:
55 success.append(project)
56 else:
57 err.append(project)
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070058 pm.end()
Wink Saville02d79452009-04-10 13:01:24 -070059
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070060 if err:
Doug Anderson3ba5f952011-04-07 12:51:04 -070061 for p in err:
Sarah Owenscecd1d82012-11-01 22:59:27 -070062 print("error: %s/: cannot checkout %s" % (p.relpath, nb),
63 file=sys.stderr)
Doug Anderson3ba5f952011-04-07 12:51:04 -070064 sys.exit(1)
65 elif not success:
Sarah Owenscecd1d82012-11-01 22:59:27 -070066 print('error: no project has branch %s' % nb, file=sys.stderr)
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070067 sys.exit(1)