start.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. class Start(Command):
  19. common = True
  20. helpSummary = "Start a new branch for development"
  21. helpUsage = """
  22. %prog <newbranchname> [<project>...]
  23. This subcommand starts a new branch of development that is automatically
  24. pulled from a remote branch.
  25. It is equivalent to the following git commands:
  26. "git branch --track <newbranchname> m/<codeline>",
  27. or
  28. "git checkout --track -b <newbranchname> m/<codeline>".
  29. All three forms set up the config entries that repo bases some of its
  30. processing on. Use %prog or git branch or checkout with --track to ensure
  31. the configuration data is set up properly.
  32. """
  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. for project in self.GetProjects(args[1:]):
  42. if not project.StartBranch(nb):
  43. err.append(project)
  44. if err:
  45. err.sort()
  46. for p in err:
  47. print >>sys.stderr, "error: cannot start in %s" % p.relpath
  48. sys.exit(1)