Make sure that the output of "stg status" is sorted
[stgit] / stgit / commands / status.py
index de88ba0..b2835ab 100644 (file)
@@ -65,6 +65,42 @@ options = [make_option('-m', '--modified',
                        action = 'store_true')]
 
 
+def status(files = None, modified = False, new = False, deleted = False,
+           conflict = False, unknown = False, noexclude = False,
+           diff_flags = []):
+    """Show the tree status
+    """
+    cache_files = git.tree_status(files,
+                                  unknown = (files == None),
+                                  noexclude = noexclude,
+                                  diff_flags = diff_flags)
+    filtered = (modified or new or deleted or conflict or unknown)
+
+    if filtered:
+        filestat = []
+        if modified:
+            filestat.append('M')
+        if new:
+            filestat.append('A')
+            filestat.append('N')
+        if deleted:
+            filestat.append('D')
+        if conflict:
+            filestat.append('C')
+        if unknown:
+            filestat.append('?')
+        cache_files = [x for x in cache_files if x[0] in filestat]
+
+    output = []
+    for st, fn in cache_files:
+        assert files == None or fn in files
+        if filtered:
+            output.append(fn)
+        else:
+            output.append('%s %s' % (st, fn))
+    for o in sorted(output):
+        out.stdout(o)
+
 def func(parser, options, args):
     """Show the tree status
     """
@@ -85,6 +121,6 @@ def func(parser, options, args):
         # No args means all files
         if not args:
             args = None
-        git.status(args, options.modified, options.new, options.deleted,
-                   options.conflict, options.unknown, options.noexclude,
-                   diff_flags = diff_flags)
+        status(args, options.modified, options.new, options.deleted,
+               options.conflict, options.unknown, options.noexclude,
+               diff_flags = diff_flags)