Add a merged upstream test for pull and push
[stgit] / stgit / commands / push.py
index 5da969a..90777c1 100644 (file)
@@ -35,8 +35,8 @@ 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)."""
+The command also notifies when the patch becomes empty (fully merged
+upstream) or is modified (three-way merged) by the 'push' operation."""
 
 options = [make_option('-a', '--all',
                        help = 'push all the unapplied patches',
@@ -49,14 +49,27 @@ options = [make_option('-a', '--all',
            make_option('--reverse',
                        help = 'push the patches in reverse order',
                        action = 'store_true'),
+           make_option('-m', '--merged',
+                       help = 'check for patches merged upstream',
+                       action = 'store_true'),
            make_option('--undo',
                        help = 'undo the last push operation',
                        action = 'store_true')]
 
 
+def is_patch_appliable(p):
+    """See if patch exists, or is already applied.
+    """
+    if p in applied:
+        raise CmdException, 'Patch "%s" is already applied' % p
+    if p not in unapplied:
+        raise CmdException, 'Patch "%s" does not exist' % p
+
 def func(parser, options, args):
     """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()
@@ -78,6 +91,7 @@ def func(parser, options, args):
     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'
@@ -85,14 +99,11 @@ def func(parser, options, args):
     if options.to:
         boundaries = options.to.split(':')
         if len(boundaries) == 1:
-            if boundaries[0] not in unapplied:
-                raise CmdException, 'Patch "%s" not unapplied' % boundaries[0]
+            is_patch_appliable(boundaries[0])
             patches = unapplied[:unapplied.index(boundaries[0])+1]
         elif len(boundaries) == 2:
-            if boundaries[0] not in unapplied:
-                raise CmdException, 'Patch "%s" not unapplied' % boundaries[0]
-            if boundaries[1] not in unapplied:
-                raise CmdException, 'Patch "%s" not unapplied' % boundaries[1]
+            is_patch_appliable(boundaries[0])
+            is_patch_appliable(boundaries[1])
             lb = unapplied.index(boundaries[0])
             hb = unapplied.index(boundaries[1])
             if lb > hb:
@@ -109,8 +120,7 @@ def func(parser, options, args):
         patches = [unapplied[0]]
     elif len(args) == 1:
         patches = args
-        if patches[0] not in unapplied:
-            raise CmdException, 'Patch "%s" not unapplied' % patches[0]
+        is_patch_appliable(patches[0])
     else:
         parser.error('incorrect number of arguments')
 
@@ -120,24 +130,6 @@ def func(parser, options, args):
     if options.reverse:
         patches.reverse()
 
-    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]
-
-    for p in patches[forwarded:]:
-        if p not in unapplied:
-            raise CmdException, 'Patch "%s" not unapplied' % p
+    push_patches(patches, options.merged)
 
-        print 'Pushing patch "%s"...' % p,
-        sys.stdout.flush()
-
-        crt_series.push_patch(p)
-
-        if crt_series.empty_patch(p):
-            print 'done (empty patch)'
-        else:
-            print 'done'
     print_crt_patch()