blob: c8a09a8e0d6169a9c7bc7b01c2acfeb2ddea81f9 [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
22class Checkout(Command):
23 common = True
24 helpSummary = "Checkout a branch for development"
25 helpUsage = """
26%prog <branchname> [<project>...]
Shawn O. Pearced33f43a2009-04-13 12:11:31 -070027"""
28 helpDescription = """
29The '%prog' command checks out an existing branch that was previously
30created by 'repo start'.
Wink Saville02d79452009-04-10 13:01:24 -070031
Shawn O. Pearced33f43a2009-04-13 12:11:31 -070032The command is equivalent to:
Wink Saville02d79452009-04-10 13:01:24 -070033
Shawn O. Pearced33f43a2009-04-13 12:11:31 -070034 repo forall [<project>...] -c git checkout <branchname>
Wink Saville02d79452009-04-10 13:01:24 -070035"""
36
Mike Frysingerae6cb082019-08-27 01:10:59 -040037 def ValidateOptions(self, opt, args):
Wink Saville02d79452009-04-10 13:01:24 -070038 if not args:
39 self.Usage()
40
Mike Frysingerae6cb082019-08-27 01:10:59 -040041 def Execute(self, opt, args):
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070042 nb = args[0]
43 err = []
Doug Anderson3ba5f952011-04-07 12:51:04 -070044 success = []
David Pursehouse5c6eeac2012-10-11 16:44:48 +090045 all_projects = self.GetProjects(args[1:])
Wink Saville02d79452009-04-10 13:01:24 -070046
David Pursehouse5c6eeac2012-10-11 16:44:48 +090047 pm = Progress('Checkout %s' % nb, len(all_projects))
48 for project in all_projects:
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070049 pm.update()
Doug Anderson3ba5f952011-04-07 12:51:04 -070050
51 status = project.CheckoutBranch(nb)
52 if status is not None:
53 if status:
54 success.append(project)
55 else:
56 err.append(project)
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070057 pm.end()
Wink Saville02d79452009-04-10 13:01:24 -070058
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070059 if err:
Doug Anderson3ba5f952011-04-07 12:51:04 -070060 for p in err:
Sarah Owenscecd1d82012-11-01 22:59:27 -070061 print("error: %s/: cannot checkout %s" % (p.relpath, nb),
62 file=sys.stderr)
Doug Anderson3ba5f952011-04-07 12:51:04 -070063 sys.exit(1)
64 elif not success:
Sarah Owenscecd1d82012-11-01 22:59:27 -070065 print('error: no project has branch %s' % nb, file=sys.stderr)
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070066 sys.exit(1)