Commit | Line | Data |
---|---|---|
994fdba7 CM |
1 | __copyright__ = """ |
2 | Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com> | |
3 | ||
4 | This program is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License version 2 as | |
6 | published by the Free Software Foundation. | |
7 | ||
8 | This program is distributed in the hope that it will be useful, | |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | GNU General Public License for more details. | |
12 | ||
13 | You should have received a copy of the GNU General Public License | |
14 | along with this program; if not, write to the Free Software | |
15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | """ | |
17 | ||
5f9f06aa KH |
18 | from stgit.commands import common |
19 | from stgit.lib import transaction | |
994fdba7 | 20 | |
575bbdae | 21 | help = 'Push or pop patches to the given one' |
33ff9cdd | 22 | kind = 'stack' |
575bbdae KH |
23 | usage = ['<patch-name>'] |
24 | description = """ | |
994fdba7 | 25 | Push/pop patches to/from the stack until the one given on the command |
625e8de7 | 26 | line becomes current.""" |
994fdba7 | 27 | |
5f9f06aa | 28 | options = [] |
994fdba7 | 29 | |
575bbdae KH |
30 | directory = common.DirectoryHasRepositoryLib() |
31 | ||
994fdba7 | 32 | def func(parser, options, args): |
994fdba7 CM |
33 | if len(args) != 1: |
34 | parser.error('incorrect number of arguments') | |
994fdba7 CM |
35 | patch = args[0] |
36 | ||
5f9f06aa | 37 | stack = directory.repository.current_stack |
a0848ecf | 38 | iw = stack.repository.default_iw |
e5075287 | 39 | trans = transaction.StackTransaction(stack, 'goto') |
5f9f06aa KH |
40 | if patch in trans.applied: |
41 | to_pop = set(trans.applied[trans.applied.index(patch)+1:]) | |
42 | assert not trans.pop_patches(lambda pn: pn in to_pop) | |
43 | elif patch in trans.unapplied: | |
44 | try: | |
45 | for pn in trans.unapplied[:trans.unapplied.index(patch)+1]: | |
46 | trans.push_patch(pn, iw) | |
47 | except transaction.TransactionHalted: | |
48 | pass | |
ca76dc5e KH |
49 | elif patch in trans.hidden: |
50 | raise common.CmdException('Cannot goto a hidden patch') | |
994fdba7 | 51 | else: |
5f9f06aa | 52 | raise common.CmdException('Patch "%s" does not exist' % patch) |
f9cc5e69 | 53 | return trans.run(iw) |