checkout.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. all = self.GetProjects(args[1:])
  36. pm = Progress('Checkout %s' % nb, len(all))
  37. for project in all:
  38. pm.update()
  39. if not project.CheckoutBranch(nb):
  40. err.append(project)
  41. pm.end()
  42. if err:
  43. if len(err) == len(all):
  44. print >>sys.stderr, 'error: no project has branch %s' % nb
  45. else:
  46. for p in err:
  47. print >>sys.stderr,\
  48. "error: %s/: cannot checkout %s" \
  49. % (p.relpath, nb)
  50. sys.exit(1)