stgit.el: Use forward-line instead of goto-line non-interactively
[stgit] / stgit / commands / top.py
index f36a0b0..4ec37b4 100644 (file)
@@ -16,22 +16,23 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-import sys, os
-from optparse import OptionParser, make_option
-
-from stgit.commands.common import *
-from stgit.utils import *
-from stgit import stack, git
-
-
-help = 'print the name of the top patch'
-usage = """%prog [options]
-
+from stgit.argparse import opt
+from stgit.commands import common
+from stgit.out import out
+from stgit import argparse
+
+help = 'Print the name of the top patch'
+kind = 'stack'
+usage = ['']
+description = """
 Print the name of the current (topmost) patch."""
 
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
+args = []
+options = [
+    opt('-b', '--branch', args = [argparse.stg_branches],
+        short = 'Use BRANCH instead of the default branch')]
 
+directory = common.DirectoryHasRepositoryLib()
 
 def func(parser, options, args):
     """Show the name of the topmost patch
@@ -39,8 +40,10 @@ def func(parser, options, args):
     if len(args) != 0:
         parser.error('incorrect number of arguments')
 
-    name = crt_series.get_current()
-    if name:
-        print name
+    stack = directory.repository.get_stack(options.branch)
+    applied = stack.patchorder.applied
+
+    if applied:
+        out.stdout(applied[-1])
     else:
-        raise CmdException, 'No patches applied'
+        raise common.CmdException, 'No patches applied'