start.py 1.9 KB

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