chiark / gitweb /
Simple rename of top-most patch
[stgit] / stgit / commands / rename.py
index d6c53be67639628d5bdbe25c2be50ceab9ce14bc..1d7c43bb65bace69988877afc62fb0c692feb4de 100644 (file)
@@ -20,14 +20,17 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
 help = 'rename a patch in the series'
-usage = """%prog [options] <oldpatch> <newpatch>
+usage = """%prog [options] [oldpatch] <newpatch>
 
-Rename <oldpatch> into <newpatch> in a series."""
+Rename <oldpatch> into <newpatch> in a series. If <oldpatch> is not given, the
+top-most patch will be renamed. """
 
+directory = DirectoryHasRepository()
 options = [make_option('-b', '--branch',
                        help = 'use BRANCH instead of the default one')]
 
@@ -35,9 +38,18 @@ options = [make_option('-b', '--branch',
 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')
 
-    out.start('Renaming patch "%s" to "%s"' % (args[0], args[1]))
-    crt_series.rename_patch(args[0], args[1])
+    out.start('Renaming patch "%s" to "%s"' % (old, new))
+    crt_series.rename_patch(old, new)
+
     out.done()