status.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. from command import PagedCommand
  16. class Status(PagedCommand):
  17. common = True
  18. helpSummary = "Show the working tree status"
  19. helpUsage = """
  20. %prog [<project>...]
  21. """
  22. helpDescription = """
  23. '%prog' compares the working tree to the staging area (aka index),
  24. and the most recent commit on this branch (HEAD), in each project
  25. specified. A summary is displayed, one line per file where there
  26. is a difference between these three states.
  27. Status Display
  28. --------------
  29. The status display is organized into three columns of information,
  30. for example if the file 'subcmds/status.py' is modified in the
  31. project 'repo' on branch 'devwork':
  32. project repo/ branch devwork
  33. -m subcmds/status.py
  34. The first column explains how the staging area (index) differs from
  35. the last commit (HEAD). Its values are always displayed in upper
  36. case and have the following meanings:
  37. -: no difference
  38. A: added (not in HEAD, in index )
  39. M: modified ( in HEAD, in index, different content )
  40. D: deleted ( in HEAD, not in index )
  41. R: renamed (not in HEAD, in index, path changed )
  42. C: copied (not in HEAD, in index, copied from another)
  43. T: mode changed ( in HEAD, in index, same content )
  44. U: unmerged; conflict resolution required
  45. The second column explains how the working directory differs from
  46. the index. Its values are always displayed in lower case and have
  47. the following meanings:
  48. -: new / unknown (not in index, in work tree )
  49. m: modified ( in index, in work tree, modified )
  50. d: deleted ( in index, not in work tree )
  51. """
  52. def Execute(self, opt, args):
  53. all = self.GetProjects(args)
  54. clean = 0
  55. on = {}
  56. for project in all:
  57. cb = project.CurrentBranch
  58. if cb:
  59. if cb not in on:
  60. on[cb] = []
  61. on[cb].append(project)
  62. branch_names = list(on.keys())
  63. branch_names.sort()
  64. for cb in branch_names:
  65. print '# on branch %s' % cb
  66. for project in all:
  67. state = project.PrintWorkTreeStatus()
  68. if state == 'CLEAN':
  69. clean += 1
  70. if len(all) == clean:
  71. print 'nothing to commit (working directory clean)'