1 from stgit
.argparse
import opt
2 from stgit
.commands
.common
import CmdException
, DirectoryHasRepository
3 from stgit
.lib
import log
, transaction
6 Copyright (C) 2008, Karl Hasselström <kha@treskal.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/.
21 help = 'Undo the last undo operation'
25 If the last command was an undo, reset the patch stack to the state it
26 had before the undo. Consecutive invocations of "stg redo" will undo
27 the effects of consecutive invocations of "stg undo".
29 It is an error to run "stg redo" if the last command was not an
40 short
='Undo the last N undos',
45 short
='Discard changes in your index/worktree',
49 directory
= DirectoryHasRepository()
52 def func(parser
, options
, args
):
53 stack
= directory
.repository
.current_stack
54 if options
.number
< 1:
55 raise CmdException('Bad number of undos to redo')
56 state
= log
.undo_state(stack
, -options
.number
)
57 trans
= transaction
.StackTransaction(
59 'redo %d' % options
.number
,
60 discard_changes
=options
.hard
,
64 log
.reset_stack(trans
, stack
.repository
.default_iw
, state
)
65 except transaction
.TransactionHalted
:
67 return trans
.run(stack
.repository
.default_iw
, allow_bad_head
=True)