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