Add automatic git-mergetool invocation to the new infrastructure
[stgit] / stgit / commands / goto.py
... / ...
CommitLineData
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
18from stgit.commands import common
19from stgit.lib import transaction
20from stgit import argparse
21from stgit.argparse import opt
22
23help = 'Push or pop patches to the given one'
24kind = 'stack'
25usage = ['<patch-name>']
26description = """
27Push/pop patches to/from the stack until the one given on the command
28line becomes current."""
29
30args = [argparse.other_applied_patches, argparse.unapplied_patches]
31options = argparse.keep_option()
32
33directory = common.DirectoryHasRepositoryLib()
34
35def func(parser, options, args):
36 if len(args) != 1:
37 parser.error('incorrect number of arguments')
38 patch = args[0]
39
40 stack = directory.repository.current_stack
41 iw = stack.repository.default_iw
42 clean_iw = (not options.keep and iw) or None
43 trans = transaction.StackTransaction(stack, 'goto',
44 check_clean_iw = clean_iw)
45 if patch in trans.applied:
46 to_pop = set(trans.applied[trans.applied.index(patch)+1:])
47 assert not trans.pop_patches(lambda pn: pn in to_pop)
48 elif patch in trans.unapplied:
49 try:
50 for pn in trans.unapplied[:trans.unapplied.index(patch)+1]:
51 trans.push_patch(pn, iw, allow_interactive = True)
52 except transaction.TransactionHalted:
53 pass
54 elif patch in trans.hidden:
55 raise common.CmdException('Cannot goto a hidden patch')
56 else:
57 raise common.CmdException('Patch "%s" does not exist' % patch)
58 return trans.run(iw)