stg import now extracts Message-ID header
[stgit.git] / stgit / commands / rename.py
blobf5fe7b3805a9fd43f2d3a6f2a90d48ad890f7640
1 from stgit.argparse import opt
2 from stgit.commands.common import CmdException, DirectoryHasRepository
3 from stgit.lib.log import log_stack_state
4 from stgit.out import out
6 __copyright__ = """
7 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 2 as
11 published by the Free Software Foundation.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, see http://www.gnu.org/licenses/.
20 """
22 help = 'Rename a patch'
23 kind = 'patch'
24 usage = ['[options] [--] [oldpatch] <newpatch>']
25 description = """
26 Rename <oldpatch> into <newpatch> in a series. If <oldpatch> is not
27 given, the top-most patch will be renamed."""
29 args = ['applied_patches', 'unapplied_patches', 'hidden_patches']
30 options = [
31 opt(
32 '-b',
33 '--branch',
34 args=['stg_branches'],
35 short='use BRANCH instead of the default one',
39 directory = DirectoryHasRepository()
42 def func(parser, options, args):
43 """Rename a patch in the series"""
44 stack = directory.repository.get_stack(options.branch)
46 if len(args) == 2:
47 old, new = args
48 elif len(args) == 1:
49 if not stack.patchorder.applied:
50 raise CmdException("No applied top patch to rename exists.")
51 old = stack.patchorder.applied[-1]
52 new = args[0]
53 else:
54 parser.error('incorrect number of arguments')
56 out.start('Renaming patch "%s" to "%s"' % (old, new))
57 stack.rename_patch(old, new)
58 log_stack_state(stack, 'rename %s to %s' % (old, new))
59 out.done()