Allow renaming of the top-most patch just by calling stg rename
<new-patch-name>, instead of stg rename <old> <new>. This is for
example helpful for those people who always have a typo or two in
their patch names.
Signed-off-by: Onno Kortmann <onno@gmx.net>
Signed-off-by: Karl Hasselström <kha@treskal.com>
help = 'rename a patch in the series'
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',
directory = DirectoryHasRepository()
options = [make_option('-b', '--branch',
def func(parser, options, args):
"""Rename a patch in the series
"""
def func(parser, options, args):
"""Rename a patch in the series
"""
+ 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')
- 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)
+