chiark / gitweb /
Rename "stg coalesce" to "stg squash"
[stgit] / stgit / commands / rename.py
index ca799c3a96316663b5f5e57ebb4f0a1e0b2f2030..8a593ac19a2f2541fd9497ba3f9dde56e9003490 100644 (file)
@@ -16,29 +16,42 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.commands.common import *
 from stgit.utils import *
-from stgit import stack, git
-
+from stgit.out import *
+from stgit import argparse, stack, git
 
 
-help = 'rename a patch in the series'
-usage = """%prog [options] <oldpatch> <newpatch>
+help = 'Rename a patch'
+kind = 'patch'
+usage = ['[options] [oldpatch] <newpatch>']
+description = """
+Rename <oldpatch> into <newpatch> in a series. If <oldpatch> is not
+given, the top-most patch will be renamed."""
 
 
-Rename <oldpatch> into <newpatch> in a series."""
-
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
+args = [argparse.applied_patches, argparse.unapplied_patches,
+        argparse.hidden_patches]
+options = [
+    opt('-b', '--branch', args = [argparse.stg_branches],
+        short = 'use BRANCH instead of the default one')]
 
 
+directory = DirectoryHasRepository(log = True)
 
 def func(parser, options, args):
     """Rename a patch in the series
     """
 
 def func(parser, options, args):
     """Rename a patch in the series
     """
-    if len(args) != 2:
+    crt = crt_series.get_current()
+
+    if len(args) == 2:
+        old, new = args
+    elif len(args) == 1:
+        if not crt:
+            raise CmdException, "No applied top patch to rename exists."
+        old, [new] = crt, args
+    else:
         parser.error('incorrect number of arguments')
 
         parser.error('incorrect number of arguments')
 
-    print 'Renaming patch "%s" -> "%s"...' % (args[0], args[1]),
-    sys.stdout.flush()
-    crt_series.rename_patch(args[0], args[1])
-    print 'done'
+    out.start('Renaming patch "%s" to "%s"' % (old, new))
+    crt_series.rename_patch(old, new)
+
+    out.done()