Avoid allowing --undo if it doesn't change anything
[stgit] / stgit / commands / push.py
index 6325483..eeb37c4 100644 (file)
@@ -66,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
@@ -116,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()