- """Pushes the given patch or all onto the series
- """
- global applied, unapplied
-
- # If --undo is passed, do the work and exit
- if options.undo:
- patch = crt_series.get_current()
- if not patch:
- raise CmdException, 'No patch to undo'
-
- print 'Undoing the "%s" push...' % patch,
- sys.stdout.flush()
- resolved_all()
- if crt_series.undo_push():
- print 'done'
- else:
- print 'done (patch unchanged)'
- print_crt_patch()
-
- return
-
- check_local_changes()
- check_conflicts()
- check_head_top_equal()
-
- applied = crt_series.get_applied()
- unapplied = crt_series.get_unapplied()
- if not unapplied:
- raise CmdException, 'No more patches to push'
-
- if options.to:
- boundaries = options.to.split(':')
- if len(boundaries) == 1:
- is_patch_appliable(boundaries[0])
- patches = unapplied[:unapplied.index(boundaries[0])+1]
- elif len(boundaries) == 2:
- is_patch_appliable(boundaries[0])
- is_patch_appliable(boundaries[1])
- lb = unapplied.index(boundaries[0])
- hb = unapplied.index(boundaries[1])
- if lb > hb:
- raise CmdException, 'Patch "%s" after "%s"' \
- % (boundaries[0], boundaries[1])
- patches = unapplied[lb:hb+1]
- else:
- raise CmdException, 'incorrect parameters to "--to"'
+ """Pushes the given patches or the first unapplied onto the stack."""
+ stack = directory.repository.current_stack
+ iw = stack.repository.default_iw
+ clean_iw = (not options.keep and iw) or None
+ trans = transaction.StackTransaction(stack, 'pop',
+ check_clean_iw = clean_iw)
+
+ if not trans.unapplied:
+ raise common.CmdException('No patches to push')
+
+ if options.all:
+ patches = list(trans.unapplied)