blob: 008850760295f845cd5bbadb30d7231a62e24fcd [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
Chad Jones87636f22012-06-14 16:53:40 -070018from git_config import IsId
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070019from git_command import git
Shawn O. Pearce0f0dfa32009-04-18 14:53:39 -070020from progress import Progress
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070021
22class Start(Command):
23 common = True
24 helpSummary = "Start a new branch for development"
25 helpUsage = """
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070026%prog <newbranchname> [--all | <project>...]
Shawn O. Pearce06e556d2009-04-18 11:19:01 -070027"""
28 helpDescription = """
29'%prog' begins a new branch of development, starting from the
30revision specified in the manifest.
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070031"""
32
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070033 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 Projectcf31fe92008-10-21 07:00:00 -070038 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. Pearce0a389e92009-04-10 16:21:18 -070047 err = []
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070048 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
55 all = self.GetProjects(projects)
Shawn O. Pearce0f0dfa32009-04-18 14:53:39 -070056
57 pm = Progress('Starting %s' % nb, len(all))
58 for project in all:
59 pm.update()
Chad Jones87636f22012-06-14 16:53:40 -070060 # 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. Pearce0a389e92009-04-10 16:21:18 -070064 if not project.StartBranch(nb):
65 err.append(project)
Shawn O. Pearce0f0dfa32009-04-18 14:53:39 -070066 pm.end()
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070067
68 if err:
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070069 for p in err:
Shawn O. Pearce89e717d2009-04-18 15:04:41 -070070 print >>sys.stderr,\
71 "error: %s/: cannot start %s" \
72 % (p.relpath, nb)
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070073 sys.exit(1)