checkout.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2009 The Android Open Source Project
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import sys
  15. from command import Command
  16. from progress import Progress
  17. class Checkout(Command):
  18. common = True
  19. helpSummary = "Checkout a branch for development"
  20. helpUsage = """
  21. %prog <branchname> [<project>...]
  22. """
  23. helpDescription = """
  24. The '%prog' command checks out an existing branch that was previously
  25. created by 'repo start'.
  26. The command is equivalent to:
  27. repo forall [<project>...] -c git checkout <branchname>
  28. """
  29. def ValidateOptions(self, opt, args):
  30. if not args:
  31. self.Usage()
  32. def Execute(self, opt, args):
  33. nb = args[0]
  34. err = []
  35. success = []
  36. all_projects = self.GetProjects(args[1:])
  37. pm = Progress('Checkout %s' % nb, len(all_projects))
  38. for project in all_projects:
  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("error: %s/: cannot checkout %s" % (p.relpath, nb),
  50. file=sys.stderr)
  51. sys.exit(1)
  52. elif not success:
  53. print('error: no project has branch %s' % nb, file=sys.stderr)
  54. sys.exit(1)