chiark / gitweb /
Allow StGIT commands to run correctly in subdirectories
[stgit] / stgit / commands / status.py
index bbfb5df843d82cf503ef61c7f451a2bc9e1292d7..5763d09356408160c7bae23c2d44475c1d4b6697 100644 (file)
@@ -25,7 +25,7 @@ from stgit import stack, git
 
 
 help = 'show the tree status'
-usage = """%prog [options] [<files...>]
+usage = """%prog [options] [<files or dirs>]
 
 Show the status of the whole working copy or the given files. The
 command also shows the files in the current directory which are not
@@ -40,6 +40,7 @@ under revision control. The files are prefixed as follows:
 A 'refresh' command clears the status of the modified, new and deleted
 files."""
 
+directory = DirectoryHasRepository()
 options = [make_option('-m', '--modified',
                        help = 'show modified files only',
                        action = 'store_true'),
@@ -71,7 +72,7 @@ def status(files = None, modified = False, new = False, deleted = False,
     """Show the tree status
     """
     cache_files = git.tree_status(files,
-                                  unknown = (files == None),
+                                  unknown = (not files),
                                   noexclude = noexclude,
                                   diff_flags = diff_flags)
     filtered = (modified or new or deleted or conflict or unknown)
@@ -91,16 +92,21 @@ def status(files = None, modified = False, new = False, deleted = False,
             filestat.append('?')
         cache_files = [x for x in cache_files if x[0] in filestat]
 
-    for fs in cache_files:
-        assert files == None or fs[1] in files
-        if not filtered:
-            out.stdout('%s %s' % (fs[0], fs[1]))
+    output = []
+    for st, fn in cache_files:
+        if filtered:
+            output.append(fn)
         else:
-            out.stdout('%s' % fs[1])
+            output.append('%s %s' % (st, fn))
+    for o in sorted(output):
+        out.stdout(o)
 
 def func(parser, options, args):
     """Show the tree status
     """
+    args = git.ls_files(args)
+    directory.cd_to_topdir()
+
     if options.reset:
         if args:
             for f in args:
@@ -115,9 +121,6 @@ def func(parser, options, args):
         else:
             diff_flags = []
 
-        # No args means all files
-        if not args:
-            args = None
         status(args, options.modified, options.new, options.deleted,
                options.conflict, options.unknown, options.noexclude,
                diff_flags = diff_flags)