Moved that status function to the status command file
[stgit] / stgit / commands / status.py
index c0b1a8e..bbfb5df 100644 (file)
@@ -57,11 +57,67 @@ options = [make_option('-m', '--modified',
                        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 = (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]
+
+    for fs in cache_files:
+        assert files == None or fs[1] in files
+        if not filtered:
+            out.stdout('%s %s' % (fs[0], fs[1]))
+        else:
+            out.stdout('%s' % fs[1])
+
 def func(parser, options, args):
     """Show the tree status
     """
-    git.status(args, options.modified, options.new, options.deleted,
-               options.conflict, options.unknown, options.noexclude)
+    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 = []
+
+        # 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)