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