'--showbranch' and '--noprefix' options for 'series'
[stgit] / stgit / commands / fold.py
index 95c962f..e87ded2 100644 (file)
@@ -28,15 +28,16 @@ usage = """%prog [options] [<file>]
 
 Apply the given GNU diff file (or the standard input) onto the top of
 the current patch. With the '--threeway' option, the patch is applied
-onto the bottom of the current patch and a three-way merged is
-performed with the current top."""
+onto the bottom of the current patch and a three-way merge is
+performed with the current top. With the --base option, the patch is
+applied onto the specified base and a three-way merged is performed
+with the current top."""
 
 options = [make_option('-t', '--threeway',
                        help = 'perform a three-way merge with the current patch',
                        action = 'store_true'),
-           make_option('-n', '--norefresh',
-                       help = 'do not refresh the current patch',
-                       action = 'store_true')]
+           make_option('-b', '--base',
+                       help = 'use BASE instead of HEAD applying the patch')]
 
 
 def func(parser, options, args):
@@ -59,7 +60,10 @@ def func(parser, options, args):
         raise CmdException, 'No patches applied'
 
     if filename:
-        print 'Folding patch "%s"...' % filename,
+        if os.path.exists(filename):
+            print 'Folding patch "%s"...' % filename,
+        else:
+            raise CmdException, 'No such file: %s' % filename
     else:
         print 'Folding patch from stdin...',
     sys.stdout.flush()
@@ -67,24 +71,10 @@ def func(parser, options, args):
     if options.threeway:
         crt_patch = crt_series.get_patch(current)
         bottom = crt_patch.get_bottom()
-        top = crt_patch.get_top()
-
-        git.switch(bottom)
-        git.apply_patch(filename)
-        fold_head = crt_series.refresh_patch(commit_only = True)
-        git.switch(top)
-
-        git.merge(bottom, top, fold_head)
+        git.apply_patch(filename = filename, base = bottom)
+    elif options.base:
+        git.apply_patch(filename = filename, base = git_id(options.base))
     else:
-        git.apply_patch(filename)
-
-    # no merge conflicts at this point, exception would have been raised
-    modified = git.local_changes()
+        git.apply_patch(filename = filename)
 
-    if not options.norefresh and modified:
-        crt_series.refresh_patch()
-
-    if modified:
-        print 'done'
-    else:
-        print 'done (unchanged)'
+    print 'done'