blob: 60ad41e0deb5b3ccfbf17d1f86a3f4a15634de8b [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
Sarah Owenscecd1d82012-11-01 22:59:27 -070016from __future__ import print_function
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070017import sys
18from command import Command
Chad Jones87636f22012-06-14 16:53:40 -070019from git_config import IsId
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070020from git_command import git
Shawn O. Pearce0f0dfa32009-04-18 14:53:39 -070021from progress import Progress
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070022
23class Start(Command):
24 common = True
25 helpSummary = "Start a new branch for development"
26 helpUsage = """
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070027%prog <newbranchname> [--all | <project>...]
Shawn O. Pearce06e556d2009-04-18 11:19:01 -070028"""
29 helpDescription = """
30'%prog' begins a new branch of development, starting from the
31revision specified in the manifest.
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070032"""
33
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070034 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 Projectcf31fe92008-10-21 07:00:00 -070039 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 Owenscecd1d82012-11-01 22:59:27 -070045 print("error: '%s' is not a valid name" % nb, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070046 sys.exit(1)
47
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070048 err = []
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070049 projects = []
50 if not opt.all:
51 projects = args[1:]
52 if len(projects) < 1:
Sarah Owenscecd1d82012-11-01 22:59:27 -070053 print("error: at least one project must be specified", file=sys.stderr)
Ficus Kirkpatrick6f6cd772009-04-22 17:27:12 -070054 sys.exit(1)
55
David Pursehouse8a68ff92012-09-24 12:15:13 +090056 all_projects = self.GetProjects(projects)
Shawn O. Pearce0f0dfa32009-04-18 14:53:39 -070057
David Pursehouse8a68ff92012-09-24 12:15:13 +090058 pm = Progress('Starting %s' % nb, len(all_projects))
59 for project in all_projects:
Shawn O. Pearce0f0dfa32009-04-18 14:53:39 -070060 pm.update()
Chad Jones87636f22012-06-14 16:53:40 -070061 # If the current revision is a specific SHA1 then we can't push back
Max Liu5fb8ed22014-06-23 14:48:16 +080062 # to it; so substitute with dest_branch if defined, or with manifest
63 # default revision instead.
Chad Jones87636f22012-06-14 16:53:40 -070064 if IsId(project.revisionExpr):
Max Liu5fb8ed22014-06-23 14:48:16 +080065 if project.dest_branch:
66 project.revisionExpr = project.dest_branch
67 else:
68 project.revisionExpr = self.manifest.default.revisionExpr
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070069 if not project.StartBranch(nb):
70 err.append(project)
Shawn O. Pearce0f0dfa32009-04-18 14:53:39 -070071 pm.end()
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070072
73 if err:
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070074 for p in err:
Sarah Owenscecd1d82012-11-01 22:59:27 -070075 print("error: %s/: cannot start %s" % (p.relpath, nb),
76 file=sys.stderr)
Shawn O. Pearce0a389e92009-04-10 16:21:18 -070077 sys.exit(1)