Improve the "publish" merge message to give slightly more information
[stgit] / stgit / commands / redo.py
CommitLineData
121c14e5
KH
1# -*- coding: utf-8 -*-
2
3__copyright__ = """
4Copyright (C) 2008, Karl Hasselström <kha@treskal.com>
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License version 2 as
8published by the Free Software Foundation.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18"""
19
20from stgit.argparse import opt
21from stgit.commands import common
22from stgit.lib import log, transaction
23
24help = 'Undo the last undo operation'
25kind = 'stack'
26usage = ['']
27description = """
28If the last command was an undo, reset the patch stack to the state it
29had before the undo. Consecutive invocations of "stg redo" will undo
30the effects of consecutive invocations of "stg undo".
31
32It is an error to run "stg redo" if the last command was not an
33undo."""
34
6c8a90e1 35args = []
121c14e5
KH
36options = [
37 opt('-n', '--number', type = 'int', metavar = 'N', default = 1,
38 short = 'Undo the last N undos'),
39 opt('--hard', action = 'store_true',
40 short = 'Discard changes in your index/worktree')]
41
42directory = common.DirectoryHasRepositoryLib()
43
44def func(parser, options, args):
45 stack = directory.repository.current_stack
46 if options.number < 1:
47 raise common.CmdException('Bad number of undos to redo')
48 state = log.undo_state(stack, -options.number)
49 trans = transaction.StackTransaction(stack, 'redo %d' % options.number,
f4e6a60e
KH
50 discard_changes = options.hard,
51 allow_bad_head = True)
121c14e5 52 try:
c70033b4 53 log.reset_stack(trans, stack.repository.default_iw, state)
121c14e5
KH
54 except transaction.TransactionHalted:
55 pass
c70033b4 56 return trans.run(stack.repository.default_iw, allow_bad_head = True)