start.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. from __future__ import print_function
  16. import sys
  17. from command import Command
  18. from git_config import IsId
  19. from git_command import git
  20. from progress import Progress
  21. class Start(Command):
  22. common = True
  23. helpSummary = "Start a new branch for development"
  24. helpUsage = """
  25. %prog <newbranchname> [--all | <project>...]
  26. """
  27. helpDescription = """
  28. '%prog' begins a new branch of development, starting from the
  29. revision specified in the manifest.
  30. """
  31. def _Options(self, p):
  32. p.add_option('--all',
  33. dest='all', action='store_true',
  34. help='begin branch in all projects')
  35. def Execute(self, opt, args):
  36. if not args:
  37. self.Usage()
  38. nb = args[0]
  39. if not git.check_ref_format('heads/%s' % nb):
  40. print("error: '%s' is not a valid name" % nb, file=sys.stderr)
  41. sys.exit(1)
  42. err = []
  43. projects = []
  44. if not opt.all:
  45. projects = args[1:]
  46. if len(projects) < 1:
  47. print("error: at least one project must be specified", file=sys.stderr)
  48. sys.exit(1)
  49. all_projects = self.GetProjects(projects)
  50. pm = Progress('Starting %s' % nb, len(all_projects))
  51. for project in all_projects:
  52. pm.update()
  53. # If the current revision is a specific SHA1 then we can't push back
  54. # to it; so substitute with dest_branch if defined, or with manifest
  55. # default revision instead.
  56. if IsId(project.revisionExpr):
  57. if project.dest_branch:
  58. project.revisionExpr = project.dest_branch
  59. else:
  60. project.revisionExpr = self.manifest.default.revisionExpr
  61. if not project.StartBranch(nb):
  62. err.append(project)
  63. pm.end()
  64. if err:
  65. for p in err:
  66. print("error: %s/: cannot start %s" % (p.relpath, nb),
  67. file=sys.stderr)
  68. sys.exit(1)