Infrastructure for current directory handling
[stgit] / stgit / commands / fold.py
index a9bb7fa..6e43101 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
@@ -33,6 +34,7 @@ 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."""
 
+directory = DirectoryHasRepository()
 options = [make_option('-t', '--threeway',
                        help = 'perform a three-way merge with the current patch',
                        action = 'store_true'),
@@ -60,18 +62,20 @@ def func(parser, options, args):
         raise CmdException, 'No patches applied'
 
     if filename:
-        print 'Folding patch "%s"...' % filename,
+        if os.path.exists(filename):
+            out.start('Folding patch "%s"' % filename)
+        else:
+            raise CmdException, 'No such file: %s' % filename
     else:
-        print 'Folding patch from stdin...',
-    sys.stdout.flush()
+        out.start('Folding patch from stdin')
 
     if options.threeway:
         crt_patch = crt_series.get_patch(current)
         bottom = crt_patch.get_bottom()
-        git.apply_patch(filename, bottom)
+        git.apply_patch(filename = filename, base = bottom)
     elif options.base:
-        git.apply_patch(filename, git_id(options.base))
+        git.apply_patch(filename = filename, base = git_id(options.base))
     else:
-        git.apply_patch(filename)
+        git.apply_patch(filename = filename)
 
-    print 'done'
+    out.done()