start.py 2.1 KB

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