X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/6972fd6b0cc82580fb94b3388e4d4879f69b09a8..737b7d8ea727d6c473be12fc7478df613391da08:/stgit/commands/goto.py?ds=sidebyside diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py index e7aa588..839b75c 100644 --- a/stgit/commands/goto.py +++ b/stgit/commands/goto.py @@ -15,54 +15,50 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -import sys, os -from optparse import OptionParser, make_option - -from stgit.commands.common import * -from stgit.utils import * -from stgit import stack, git - - -help = 'push or pop patches to the given one' -usage = """%prog [options] - +from stgit.commands import common +from stgit.lib import transaction +from stgit import argparse +from stgit.argparse import opt + +help = 'Push or pop patches to the given one' +kind = 'stack' +usage = [''] +description = """ Push/pop patches to/from the stack until the one given on the command -line becomes current. This is a shortcut for the 'push --to' or 'pop ---to' commands. There is no '--undo' option for 'goto'. Use the 'push' -command for this.""" +line becomes current.""" -directory = DirectoryHasRepository() -options = [make_option('-k', '--keep', - help = 'keep the local changes when popping patches', - action = 'store_true')] +args = [argparse.other_applied_patches, argparse.unapplied_patches] +options = argparse.keep_option() + argparse.merged_option() +directory = common.DirectoryHasRepositoryLib() def func(parser, options, args): - """Pushes the given patch or all onto the series - """ if len(args) != 1: parser.error('incorrect number of arguments') - - check_conflicts() - check_head_top_equal(crt_series) - - if not options.keep: - check_local_changes() - - applied = crt_series.get_applied() - unapplied = crt_series.get_unapplied() patch = args[0] - if patch in applied: - applied.reverse() - patches = applied[:applied.index(patch)] - pop_patches(crt_series, patches, options.keep) - elif patch in unapplied: - if options.keep: - raise CmdException, 'Cannot use --keep with patch pushing' - patches = unapplied[:unapplied.index(patch)+1] - push_patches(crt_series, patches) + stack = directory.repository.current_stack + iw = stack.repository.default_iw + clean_iw = (not options.keep and iw) or None + trans = transaction.StackTransaction(stack, 'goto', + check_clean_iw = clean_iw) + if patch in trans.applied: + to_pop = set(trans.applied[trans.applied.index(patch)+1:]) + assert not trans.pop_patches(lambda pn: pn in to_pop) + elif patch in trans.unapplied: + try: + to_push = trans.unapplied[:trans.unapplied.index(patch)+1] + if options.merged: + merged = set(trans.check_merged(to_push)) + else: + merged = set() + for pn in to_push: + trans.push_patch(pn, iw, allow_interactive = True, + already_merged = pn in merged) + except transaction.TransactionHalted: + pass + elif patch in trans.hidden: + raise common.CmdException('Cannot goto a hidden patch') else: - raise CmdException, 'Patch "%s" does not exist' % patch - - print_crt_patch(crt_series) + raise common.CmdException('Patch "%s" does not exist' % patch) + return trans.run(iw)