1 from stgit
import utils
2 from stgit
.argparse
import opt
, patch_range
3 from stgit
.commands
.common
import CmdException
, DirectoryHasRepository
4 from stgit
.lib
import log
, transaction
7 Copyright (C) 2008, Karl Hasselström <kha@treskal.com>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 2 as
11 published by the Free Software Foundation.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, see http://www.gnu.org/licenses/.
22 help = 'Reset the patch stack to an earlier state'
24 usage
= ['[options] [--] [<state> [<patchnames>]]']
26 Reset the patch stack to an earlier state. If no state is specified,
27 reset only the changes in the worktree.
29 The state is specified with a commit id from a stack log; "stg log" lets
30 you view this log, and "stg reset" lets you reset to any state you see
31 in the log. If one or more patch names are given, reset only those
32 patches, and leave the rest alone."""
34 args
= [patch_range('applied_patches', 'unapplied_patches', 'hidden_patches')]
39 short
='Discard changes in your index/worktree',
43 directory
= DirectoryHasRepository()
46 def func(parser
, options
, args
):
47 stack
= directory
.repository
.current_stack
48 iw
= stack
.repository
.default_iw
50 ref
, patches
= args
[0], args
[1:]
51 state
= log
.get_stack_state(
52 stack
.repository
, ref
, stack
.repository
.rev_parse(ref
)
55 iw
.checkout_hard(stack
.head
.data
.tree
)
56 return utils
.STGIT_SUCCESS
58 raise CmdException('Wrong options or number of arguments')
60 trans
= transaction
.StackTransaction(
63 discard_changes
=options
.hard
,
68 log
.reset_stack_partially(trans
, iw
, state
, patches
)
70 log
.reset_stack(trans
, iw
, state
)
71 except transaction
.TransactionHalted
:
73 return trans
.run(iw
, allow_bad_head
=not patches
)