stgit.el: Handle errors in first phase of stgit squash
[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
6c8a90e1 20from stgit import argparse
994fdba7 21
575bbdae 22help = 'Push or pop patches to the given one'
33ff9cdd 23kind = 'stack'
575bbdae
KH
24usage = ['<patch-name>']
25description = """
994fdba7 26Push/pop patches to/from the stack until the one given on the command
625e8de7 27line becomes current."""
994fdba7 28
6c8a90e1 29args = [argparse.other_applied_patches, argparse.unapplied_patches]
5f9f06aa 30options = []
994fdba7 31
575bbdae
KH
32directory = common.DirectoryHasRepositoryLib()
33
994fdba7 34def func(parser, options, args):
994fdba7
CM
35 if len(args) != 1:
36 parser.error('incorrect number of arguments')
994fdba7
CM
37 patch = args[0]
38
5f9f06aa 39 stack = directory.repository.current_stack
a0848ecf 40 iw = stack.repository.default_iw
e5075287 41 trans = transaction.StackTransaction(stack, 'goto')
5f9f06aa
KH
42 if patch in trans.applied:
43 to_pop = set(trans.applied[trans.applied.index(patch)+1:])
44 assert not trans.pop_patches(lambda pn: pn in to_pop)
45 elif patch in trans.unapplied:
46 try:
47 for pn in trans.unapplied[:trans.unapplied.index(patch)+1]:
48 trans.push_patch(pn, iw)
49 except transaction.TransactionHalted:
50 pass
ca76dc5e
KH
51 elif patch in trans.hidden:
52 raise common.CmdException('Cannot goto a hidden patch')
994fdba7 53 else:
5f9f06aa 54 raise common.CmdException('Patch "%s" does not exist' % patch)
f9cc5e69 55 return trans.run(iw)