abandon.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #
  2. # Copyright (C) 2008 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 git_command import git
  18. from progress import Progress
  19. class Abandon(Command):
  20. common = True
  21. helpSummary = "Permanently abandon a development branch"
  22. helpUsage = """
  23. %prog <branchname> [<project>...]
  24. This subcommand permanently abandons a development branch by
  25. deleting it (and all its history) from your local repository.
  26. It is equivalent to "git branch -D <branchname>".
  27. """
  28. def Execute(self, opt, args):
  29. if not args:
  30. self.Usage()
  31. nb = args[0]
  32. if not git.check_ref_format('heads/%s' % nb):
  33. print >>sys.stderr, "error: '%s' is not a valid name" % nb
  34. sys.exit(1)
  35. nb = args[0]
  36. err = []
  37. success = []
  38. all = self.GetProjects(args[1:])
  39. pm = Progress('Abandon %s' % nb, len(all))
  40. for project in all:
  41. pm.update()
  42. status = project.AbandonBranch(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 >>sys.stderr,\
  52. "error: %s/: cannot abandon %s" \
  53. % (p.relpath, nb)
  54. sys.exit(1)
  55. elif not success:
  56. print >>sys.stderr, 'error: no project has branch %s' % nb
  57. sys.exit(1)
  58. else:
  59. print >>sys.stderr, 'Abandoned in %d project(s):\n %s' % (
  60. len(success), '\n '.join(p.relpath for p in success))