The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2008 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 |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 17 | import sys |
| 18 | from command import Command |
Chad Jones | 87636f2 | 2012-06-14 16:53:40 -0700 | [diff] [blame] | 19 | from git_config import IsId |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | from git_command import git |
Shawn O. Pearce | 0f0dfa3 | 2009-04-18 14:53:39 -0700 | [diff] [blame] | 21 | from progress import Progress |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | |
| 23 | class Start(Command): |
| 24 | common = True |
| 25 | helpSummary = "Start a new branch for development" |
| 26 | helpUsage = """ |
Ficus Kirkpatrick | 6f6cd77 | 2009-04-22 17:27:12 -0700 | [diff] [blame] | 27 | %prog <newbranchname> [--all | <project>...] |
Shawn O. Pearce | 06e556d | 2009-04-18 11:19:01 -0700 | [diff] [blame] | 28 | """ |
| 29 | helpDescription = """ |
| 30 | '%prog' begins a new branch of development, starting from the |
| 31 | revision specified in the manifest. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 32 | """ |
| 33 | |
Ficus Kirkpatrick | 6f6cd77 | 2009-04-22 17:27:12 -0700 | [diff] [blame] | 34 | def _Options(self, p): |
| 35 | p.add_option('--all', |
| 36 | dest='all', action='store_true', |
| 37 | help='begin branch in all projects') |
| 38 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 39 | def Execute(self, opt, args): |
| 40 | if not args: |
| 41 | self.Usage() |
| 42 | |
| 43 | nb = args[0] |
| 44 | if not git.check_ref_format('heads/%s' % nb): |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 45 | print("error: '%s' is not a valid name" % nb, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 46 | sys.exit(1) |
| 47 | |
Shawn O. Pearce | 0a389e9 | 2009-04-10 16:21:18 -0700 | [diff] [blame] | 48 | err = [] |
Ficus Kirkpatrick | 6f6cd77 | 2009-04-22 17:27:12 -0700 | [diff] [blame] | 49 | projects = [] |
| 50 | if not opt.all: |
| 51 | projects = args[1:] |
| 52 | if len(projects) < 1: |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 53 | print("error: at least one project must be specified", file=sys.stderr) |
Ficus Kirkpatrick | 6f6cd77 | 2009-04-22 17:27:12 -0700 | [diff] [blame] | 54 | sys.exit(1) |
| 55 | |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 56 | all_projects = self.GetProjects(projects) |
Shawn O. Pearce | 0f0dfa3 | 2009-04-18 14:53:39 -0700 | [diff] [blame] | 57 | |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 58 | pm = Progress('Starting %s' % nb, len(all_projects)) |
| 59 | for project in all_projects: |
Shawn O. Pearce | 0f0dfa3 | 2009-04-18 14:53:39 -0700 | [diff] [blame] | 60 | pm.update() |
Chad Jones | 87636f2 | 2012-06-14 16:53:40 -0700 | [diff] [blame] | 61 | # If the current revision is a specific SHA1 then we can't push back |
| 62 | # to it so substitute the manifest default revision instead. |
| 63 | if IsId(project.revisionExpr): |
| 64 | project.revisionExpr = self.manifest.default.revisionExpr |
Shawn O. Pearce | 0a389e9 | 2009-04-10 16:21:18 -0700 | [diff] [blame] | 65 | if not project.StartBranch(nb): |
| 66 | err.append(project) |
Shawn O. Pearce | 0f0dfa3 | 2009-04-18 14:53:39 -0700 | [diff] [blame] | 67 | pm.end() |
Shawn O. Pearce | 0a389e9 | 2009-04-10 16:21:18 -0700 | [diff] [blame] | 68 | |
| 69 | if err: |
Shawn O. Pearce | 0a389e9 | 2009-04-10 16:21:18 -0700 | [diff] [blame] | 70 | for p in err: |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 71 | print("error: %s/: cannot start %s" % (p.relpath, nb), |
| 72 | file=sys.stderr) |
Shawn O. Pearce | 0a389e9 | 2009-04-10 16:21:18 -0700 | [diff] [blame] | 73 | sys.exit(1) |