Infrastructure for current directory handling
[stgit] / stgit / commands / sync.py
index 8359061..8a31c29 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 = DirectoryHasRepository()
 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'),
@@ -66,12 +68,10 @@ 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()
 
         out.start('Undoing the sync of "%s"' % crt_series.get_current())
@@ -80,12 +80,9 @@ def func(parser, options, args):
         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()