blob: 51ac48333310e09eb1694d25f2a67cc80332c20c [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
37 def Execute(self, opt, args):
38 if not args:
39 self.Usage()
40
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070041 nb = args[0]
42 err = []
Doug Anderson3ba5f952011-04-07 12:51:04 -070043 success = []
David Pursehouse5c6eeac2012-10-11 16:44:48 +090044 all_projects = self.GetProjects(args[1:])
Wink Saville02d79452009-04-10 13:01:24 -070045
David Pursehouse5c6eeac2012-10-11 16:44:48 +090046 pm = Progress('Checkout %s' % nb, len(all_projects))
47 for project in all_projects:
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070048 pm.update()
Doug Anderson3ba5f952011-04-07 12:51:04 -070049
50 status = project.CheckoutBranch(nb)
51 if status is not None:
52 if status:
53 success.append(project)
54 else:
55 err.append(project)
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070056 pm.end()
Wink Saville02d79452009-04-10 13:01:24 -070057
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070058 if err:
Doug Anderson3ba5f952011-04-07 12:51:04 -070059 for p in err:
Sarah Owenscecd1d82012-11-01 22:59:27 -070060 print("error: %s/: cannot checkout %s" % (p.relpath, nb),
61 file=sys.stderr)
Doug Anderson3ba5f952011-04-07 12:51:04 -070062 sys.exit(1)
63 elif not success:
Sarah Owenscecd1d82012-11-01 22:59:27 -070064 print('error: no project has branch %s' % nb, file=sys.stderr)
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070065 sys.exit(1)