stgit.el: Use forward-line instead of goto-line non-interactively
[stgit] / stgit / commands / prev.py
CommitLineData
26e3ed6d
HE
1__copyright__ = """
2Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License version 2 as
6published by the Free Software Foundation.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16"""
17
18from stgit.argparse import opt
19from stgit.commands import common
20from stgit.out import out
21from stgit import argparse
22
23help = 'Print the name of the previous patch'
24kind = 'stack'
25usage = ['']
26description = """
27Print the name of the previous patch."""
28
29args = []
30options = [
31 opt('-b', '--branch', args = [argparse.stg_branches],
32 short = 'Use BRANCH instead of the default branch')]
33
34directory = common.DirectoryHasRepositoryLib()
35
36def func(parser, options, args):
37 """Show the name of the previous patch
38 """
39 if len(args) != 0:
40 parser.error('incorrect number of arguments')
41
42 stack = directory.repository.get_stack(options.branch)
43 applied = stack.patchorder.applied
44
45 if applied and len(applied) >= 2:
46 out.stdout(applied[-2])
47 else:
48 raise common.CmdException, 'Not enough applied patches'