chiark / gitweb /
Allow StGIT commands to run correctly in subdirectories
[stgit] / stgit / commands / status.py
index 65bffacb312f1f14f69c5f189bc53f0a63dd7dd7..5763d09356408160c7bae23c2d44475c1d4b6697 100644 (file)
@@ -25,8 +25,22 @@ 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
+under revision control. The files are prefixed as follows:
+
+  M - locally modified
+  N - newly added to the repository
+  D - deleted from the repository
+  C - conflict
+  ? - unknown
+
+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'),
@@ -41,11 +55,72 @@ options = [make_option('-m', '--modified',
                        action = 'store_true'),
            make_option('-u', '--unknown',
                        help = 'show unknown files only',
+                       action = 'store_true'),
+           make_option('-x', '--noexclude',
+                       help = 'do not exclude any files from listing',
+                       action = 'store_true'),
+           make_option('-O', '--diff-opts',
+                       help = 'options to pass to git-diff'),
+           make_option('--reset',
+                       help = 'reset the current tree changes',
                        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 = (not files),
+                                  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:
+        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
     """
-    git.status(args, options.modified, options.new, options.deleted,
-               options.conflict, options.unknown)
+    args = git.ls_files(args)
+    directory.cd_to_topdir()
+
+    if options.reset:
+        if args:
+            for f in args:
+                resolved(f)
+            git.reset(args)
+        else:
+            resolved_all()
+            git.reset()
+    else:
+        if options.diff_opts:
+            diff_flags = options.diff_opts.split()
+        else:
+            diff_flags = []
+
+        status(args, options.modified, options.new, options.deleted,
+               options.conflict, options.unknown, options.noexclude,
+               diff_flags = diff_flags)