Wink Saville | 02d7945 | 2009-04-10 13:01:24 -0700 | [diff] [blame] | 1 | # |
| 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 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame^] | 16 | from __future__ import print_function |
Wink Saville | 02d7945 | 2009-04-10 13:01:24 -0700 | [diff] [blame] | 17 | import sys |
| 18 | from command import Command |
Shawn O. Pearce | 89e717d | 2009-04-18 15:04:41 -0700 | [diff] [blame] | 19 | from progress import Progress |
Wink Saville | 02d7945 | 2009-04-10 13:01:24 -0700 | [diff] [blame] | 20 | |
| 21 | class Checkout(Command): |
| 22 | common = True |
| 23 | helpSummary = "Checkout a branch for development" |
| 24 | helpUsage = """ |
| 25 | %prog <branchname> [<project>...] |
Shawn O. Pearce | d33f43a | 2009-04-13 12:11:31 -0700 | [diff] [blame] | 26 | """ |
| 27 | helpDescription = """ |
| 28 | The '%prog' command checks out an existing branch that was previously |
| 29 | created by 'repo start'. |
Wink Saville | 02d7945 | 2009-04-10 13:01:24 -0700 | [diff] [blame] | 30 | |
Shawn O. Pearce | d33f43a | 2009-04-13 12:11:31 -0700 | [diff] [blame] | 31 | The command is equivalent to: |
Wink Saville | 02d7945 | 2009-04-10 13:01:24 -0700 | [diff] [blame] | 32 | |
Shawn O. Pearce | d33f43a | 2009-04-13 12:11:31 -0700 | [diff] [blame] | 33 | repo forall [<project>...] -c git checkout <branchname> |
Wink Saville | 02d7945 | 2009-04-10 13:01:24 -0700 | [diff] [blame] | 34 | """ |
| 35 | |
| 36 | def Execute(self, opt, args): |
| 37 | if not args: |
| 38 | self.Usage() |
| 39 | |
Shawn O. Pearce | 89e717d | 2009-04-18 15:04:41 -0700 | [diff] [blame] | 40 | nb = args[0] |
| 41 | err = [] |
Doug Anderson | 3ba5f95 | 2011-04-07 12:51:04 -0700 | [diff] [blame] | 42 | success = [] |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 43 | all_projects = self.GetProjects(args[1:]) |
Wink Saville | 02d7945 | 2009-04-10 13:01:24 -0700 | [diff] [blame] | 44 | |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 45 | pm = Progress('Checkout %s' % nb, len(all_projects)) |
| 46 | for project in all_projects: |
Shawn O. Pearce | 89e717d | 2009-04-18 15:04:41 -0700 | [diff] [blame] | 47 | pm.update() |
Doug Anderson | 3ba5f95 | 2011-04-07 12:51:04 -0700 | [diff] [blame] | 48 | |
| 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. Pearce | 89e717d | 2009-04-18 15:04:41 -0700 | [diff] [blame] | 55 | pm.end() |
Wink Saville | 02d7945 | 2009-04-10 13:01:24 -0700 | [diff] [blame] | 56 | |
Shawn O. Pearce | 89e717d | 2009-04-18 15:04:41 -0700 | [diff] [blame] | 57 | if err: |
Doug Anderson | 3ba5f95 | 2011-04-07 12:51:04 -0700 | [diff] [blame] | 58 | for p in err: |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame^] | 59 | print("error: %s/: cannot checkout %s" % (p.relpath, nb), |
| 60 | file=sys.stderr) |
Doug Anderson | 3ba5f95 | 2011-04-07 12:51:04 -0700 | [diff] [blame] | 61 | sys.exit(1) |
| 62 | elif not success: |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame^] | 63 | print('error: no project has branch %s' % nb, file=sys.stderr) |
Shawn O. Pearce | 89e717d | 2009-04-18 15:04:41 -0700 | [diff] [blame] | 64 | sys.exit(1) |