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