checkout.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #
  2. # Copyright (C) 2009 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 progress import Progress
  18. class Checkout(Command):
  19. common = True
  20. helpSummary = "Checkout a branch for development"
  21. helpUsage = """
  22. %prog <branchname> [<project>...]
  23. """
  24. helpDescription = """
  25. The '%prog' command checks out an existing branch that was previously
  26. created by 'repo start'.
  27. The command is equivalent to:
  28. repo forall [<project>...] -c git checkout <branchname>
  29. """
  30. def Execute(self, opt, args):
  31. if not args:
  32. self.Usage()
  33. nb = args[0]
  34. err = []
  35. success = []
  36. all = self.GetProjects(args[1:])
  37. pm = Progress('Checkout %s' % nb, len(all))
  38. for project in all:
  39. pm.update()
  40. status = project.CheckoutBranch(nb)
  41. if status is not None:
  42. if status:
  43. success.append(project)
  44. else:
  45. err.append(project)
  46. pm.end()
  47. if err:
  48. for p in err:
  49. print >>sys.stderr,\
  50. "error: %s/: cannot checkout %s" \
  51. % (p.relpath, nb)
  52. sys.exit(1)
  53. elif not success:
  54. print >>sys.stderr, 'error: no project has branch %s' % nb
  55. sys.exit(1)