Invoke the correct interactive editor
[stgit] / stgit / commands / reset.py
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 git, log, transaction
23 from stgit.out import out
24
25 help = 'Reset the patch stack to an earlier state'
26 kind = 'stack'
27 usage = ['[options] <state> [<patchnames>]']
28 description = """
29 Reset the patch stack to an earlier state. The state is specified with
30 a commit id from a stack log; "stg log" lets you view this log, and
31 "stg reset" lets you reset to any state you see in the log.
32
33 If one or more patch names are given, reset only those patches, and
34 leave the rest alone."""
35
36 options = [
37 opt('--hard', action = 'store_true',
38 short = 'Discard changes in your index/worktree')]
39
40 directory = common.DirectoryHasRepositoryLib()
41
42 def func(parser, options, args):
43 stack = directory.repository.current_stack
44 if len(args) >= 1:
45 ref, patches = args[0], args[1:]
46 state = log.get_log_entry(stack.repository, ref,
47 stack.repository.rev_parse(ref))
48 else:
49 raise common.CmdException('Wrong number of arguments')
50 trans = transaction.StackTransaction(stack, 'reset',
51 discard_changes = options.hard,
52 allow_bad_head = True)
53 try:
54 if patches:
55 log.reset_stack_partially(trans, stack.repository.default_iw,
56 state, patches)
57 else:
58 log.reset_stack(trans, stack.repository.default_iw, state)
59 except transaction.TransactionHalted:
60 pass
61 return trans.run(stack.repository.default_iw, allow_bad_head = not patches)