Avoid allowing --undo if it doesn't change anything
[stgit] / stgit / commands / push.py
index 65462b3..eeb37c4 100644 (file)
@@ -25,7 +25,18 @@ from stgit import stack, git
 
 
 help = 'push a patch on top of the series'
-usage = '%prog [options] [<name>]'
+usage = """%prog [options] [<name>]
+
+Push a patch (defaulting to the first unapplied one) or range of
+patches to the stack. The 'push' operation allows patch reordering by
+commuting them with the three-way merge algorithm. If the result of
+the 'push' operation is not acceptable or if there are too many
+conflicts, the '--undo' option can be used to revert the patch and the
+tree to the state before the operation. Conflicts raised during the
+push operation have to be fixed and the 'resolved' command run.
+
+The 'push' command also notifies when the patch becomes empty after
+the merge operation (i.e. it was fully merged upstream)."""
 
 options = [make_option('-a', '--all',
                        help = 'push all the unapplied patches',
@@ -55,8 +66,10 @@ def func(parser, options, args):
         print 'Undoing the "%s" push...' % patch,
         sys.stdout.flush()
         resolved_all()
-        crt_series.undo_push()
-        print 'done'
+        if crt_series.undo_push():
+            print 'done'
+        else:
+            print 'done (patch unchanged)'
         print_crt_patch()
 
         return
@@ -105,7 +118,21 @@ def func(parser, options, args):
     if options.reverse:
         patches.reverse()
 
-    for p in patches:
+    print 'Trying fast-forward...'
+
+    forwarded = crt_series.forward_patches(patches)
+    if forwarded > 1:
+        print 'Fast-forwarded patches "%s" - "%s"' % (patches[0],
+                                                      patches[forwarded - 1])
+    elif forwarded == 1:
+        print 'Fast-forwarded patch "%s"' % patches[0]
+    else:
+        print 'Fast-forwarding failed, using normal pushing'
+
+    for p in patches[forwarded:]:
+        if p not in unapplied:
+            raise CmdException, 'Patch "%s" not unapplied' % p
+
         print 'Pushing patch "%s"...' % p,
         sys.stdout.flush()