stg import now extracts Message-ID header
[stgit.git] / stgit / commands / top.py
blobc6fd4a32f2fdd2cbf1cbe44692c7aa453067f2f9
1 from stgit.argparse import opt
2 from stgit.commands.common import CmdException, DirectoryHasRepository
3 from stgit.out import out
5 __copyright__ = """
6 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see http://www.gnu.org/licenses/.
19 """
21 help = 'Print the name of the top patch'
22 kind = 'stack'
23 usage = ['']
24 description = """
25 Print the name of the current (topmost) patch."""
27 args = []
28 options = [
29 opt(
30 '-b',
31 '--branch',
32 args=['stg_branches'],
33 short='Use BRANCH instead of the default branch',
37 directory = DirectoryHasRepository()
40 def func(parser, options, args):
41 """Show the name of the topmost patch"""
42 if len(args) != 0:
43 parser.error('incorrect number of arguments')
45 stack = directory.repository.get_stack(options.branch)
46 applied = stack.patchorder.applied
48 if applied:
49 out.stdout(applied[-1])
50 else:
51 raise CmdException('No patches applied')