checkout.py 1.8 KB

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