Make sure the refid given to 'mail' has the angle brackets
[stgit] / stgit / commands / sync.py
index db52bcd..660ee41 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 import stgit.commands.common
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
@@ -35,10 +36,11 @@ in the series must apply cleanly.
 
 The sync operation can be reverted for individual patches with --undo."""
 
+directory = DirectoryGotoToplevel()
 options = [make_option('-a', '--all',
                        help = 'synchronise all the patches',
                        action = 'store_true'),
-           make_option('-b', '--branch',
+           make_option('-B', '--ref-branch',
                        help = 'syncronise patches with BRANCH'),
            make_option('-s', '--series',
                        help = 'syncronise patches with SERIES'),
@@ -49,7 +51,7 @@ options = [make_option('-a', '--all',
 def __check_all():
     check_local_changes()
     check_conflicts()
-    check_head_top_equal()
+    check_head_top_equal(crt_series)
 
 def __branch_merge_patch(remote_series, pname):
     """Merge a patch from a remote branch into the current tree.
@@ -66,29 +68,21 @@ def __series_merge_patch(base, patchdir, pname):
 def func(parser, options, args):
     """Synchronise a range of patches
     """
-    global crt_series
-
     if options.undo:
-        if options.branch or options.series:
+        if options.ref_branch or options.series:
             raise CmdException, \
-                  '--undo cannot be specified with --branch or --series'
+                  '--undo cannot be specified with --ref-branch or --series'
         __check_all()
 
-        print 'Undoing the "%s" sync...' % crt_series.get_current(),
-        sys.stdout.flush()
-
+        out.start('Undoing the sync of "%s"' % crt_series.get_current())
         crt_series.undo_refresh()
         git.reset()
-
-        print 'done'
+        out.done()
         return
 
-    if options.branch:
-        # the main function already made crt_series to be the remote
-        # branch
-        remote_series = crt_series
-        stgit.commands.common.crt_series = crt_series = stack.Series()
-        if options.branch == crt_series.get_branch():
+    if options.ref_branch:
+        remote_series = stack.Series(options.ref_branch)
+        if options.ref_branch == crt_series.get_name():
             raise CmdException, 'Cannot synchronise with the current branch'
         remote_patches = remote_series.get_applied()
 
@@ -137,18 +131,17 @@ def func(parser, options, args):
     # pop to the one before the first patch to be synchronised
     popped = applied[applied.index(sync_patches[0]) + 1:]
     if popped:
-        pop_patches(popped[::-1])
+        pop_patches(crt_series, popped[::-1])
 
     for p in sync_patches:
         if p in popped:
             # push to this patch
             idx = popped.index(p) + 1
-            push_patches(popped[:idx])
+            push_patches(crt_series, popped[:idx])
             del popped[:idx]
 
         # the actual sync
-        print 'Synchronising "%s"...' % p,
-        sys.stdout.flush()
+        out.start('Synchronising "%s"' % p)
 
         patch = crt_series.get_patch(p)
         bottom = patch.get_bottom()
@@ -167,10 +160,10 @@ def func(parser, options, args):
             # backup information was already reset above
             crt_series.refresh_patch(cache_update = False, backup = False,
                                      log = 'sync')
-            print 'done (updated)'
+            out.done('updated')
         else:
-            print 'done'
+            out.done()
 
     # push the remaining patches
     if popped:
-        push_patches(popped)
+        push_patches(crt_series, popped)