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 | ||
6c8a90e1 | 35 | args = [] |
121c14e5 KH |
36 | options = [ |
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 | ||
42 | directory = common.DirectoryHasRepositoryLib() | |
43 | ||
44 | def 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) |