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