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