Don't use / as separatar since it is common i branch names
[stgit] / stgit / commands / refresh.py
index 2949ecb..77dcbda 100644 (file)
@@ -66,6 +66,8 @@ options = [make_option('-f', '--force',
            make_option('--commemail',
                        help = 'use COMMEMAIL as the committer ' \
                        'e-mail'),
+           make_option('-p', '--patch',
+                       help = 'refresh (applied) PATCH instead of the top one'),
            make_option('--sign',
                        help = 'add Signed-off-by line',
                        action = 'store_true'),
@@ -75,23 +77,30 @@ options = [make_option('-f', '--force',
 
 
 def func(parser, options, args):
-    autoresolved = config.get('stgit', 'autoresolved')
+    autoresolved = config.get('stgit.autoresolved')
 
     if autoresolved != 'yes':
         check_conflicts()
 
-    patch = crt_series.get_current()
-    if not patch:
-        raise CmdException, 'No patches applied'
+    if options.patch:
+        if args:
+            raise CmdException, \
+                  'Only full refresh is available with the --patch option'
+        patch = options.patch
+        if not crt_series.patch_applied(patch):
+            raise CmdException, 'Patches "%s" not applied' % patch
+    else:
+        patch = crt_series.get_current()
+        if not patch:
+            raise CmdException, 'No patches applied'
 
     if not options.force:
         check_head_top_equal()
 
     if options.undo:
-        print 'Undoing the "%s" refresh...' % patch,
-        sys.stdout.flush()
+        out.start('Undoing the refresh of "%s"' % patch)
         crt_series.undo_refresh()
-        print 'done'
+        out.done()
         return
 
     if options.author:
@@ -112,8 +121,13 @@ def func(parser, options, args):
            or options.authname or options.authemail or options.authdate \
            or options.commname or options.commemail \
            or options.sign or options.ack:
-        print 'Refreshing patch "%s"...' % patch,
-        sys.stdout.flush()
+
+        if options.patch:
+            applied = crt_series.get_applied()
+            between = applied[:applied.index(patch):-1]
+            pop_patches(between, keep = True)
+
+        out.start('Refreshing patch "%s"' % patch)
 
         if autoresolved == 'yes':
             resolved_all()
@@ -128,6 +142,13 @@ def func(parser, options, args):
                                  committer_email = options.commemail,
                                  backup = True, sign_str = sign_str)
 
-        print 'done'
+        if crt_series.empty_patch(patch):
+            out.done('empty patch')
+        else:
+            out.done()
+
+        if options.patch:
+            between.reverse()
+            push_patches(between)
     else:
-        print 'Patch "%s" is already up to date' % patch
+        out.info('Patch "%s" is already up to date' % patch)