blob: ae2985d2d924899a52ee53d1cd02d7b90c1e2895 [file] [log] [blame]
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001#
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
16import sys
17from command import Command
18from git_command import git
Shawn O. Pearce0f0dfa32009-04-18 14:53:39 -070019from progress import Progress
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070020
21class Start(Command):
22 common = True
23 helpSummary = "Start a new branch for development"
24 helpUsage = """
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070025%prog <newbranchname> [--all | <project>...]
Shawn O. Pearce06e556d2009-04-18 11:19:01 -070026"""
27 helpDescription = """
28'%prog' begins a new branch of development, starting from the
29revision specified in the manifest.
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070030"""
31
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070032 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 Projectcf31fe92008-10-21 07:00:00 -070037 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. Pearce0a389e92009-04-10 16:21:18 -070046 err = []
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070047 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. Pearce0f0dfa32009-04-18 14:53:39 -070055
56 pm = Progress('Starting %s' % nb, len(all))
57 for project in all:
58 pm.update()
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070059 if not project.StartBranch(nb):
60 err.append(project)
Shawn O. Pearce0f0dfa32009-04-18 14:53:39 -070061 pm.end()
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070062
63 if err:
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070064 for p in err:
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070065 print >>sys.stderr,\
66 "error: %s/: cannot start %s" \
67 % (p.relpath, nb)
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070068 sys.exit(1)