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