chiark / gitweb /
Remove --undo flags from stg commands and docs
[stgit] / stgit / commands / sync.py
index cbacef72e2844324550ce5db28bf47f5e9274200..966ac553635fece01886db34f230da86437717a5 100644 (file)
@@ -16,37 +16,32 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
 import stgit.commands.common
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 
-
-help = 'synchronise patches with a branch or a series'
-usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
-
+help = 'Synchronise patches with a branch or a series'
+kind = 'patch'
+usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]']
+description = """
 For each of the specified patches perform a three-way merge with the
 same patch in the specified branch or series. The command can be used
 for keeping patches on several branches in sync. Note that the
 operation may fail for some patches because of conflicts. The patches
-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 applied patches',
-                       action = 'store_true'),
-           make_option('-B', '--ref-branch',
-                       help = 'syncronise patches with BRANCH'),
-           make_option('-s', '--series',
-                       help = 'syncronise patches with SERIES'),
-           make_option('--undo',
-                       help = 'undo the synchronisation of the current patch',
-                       action = 'store_true')]
+in the series must apply cleanly."""
+
+options = [
+    opt('-a', '--all', action = 'store_true',
+        short = 'Synchronise all the applied patches'),
+    opt('-B', '--ref-branch',
+        short = 'Syncronise patches with BRANCH'),
+    opt('-s', '--series',
+        short = 'Syncronise patches with SERIES')]
+
+directory = DirectoryGotoToplevel(log = True)
 
 def __check_all():
     check_local_changes()
@@ -57,7 +52,7 @@ def __branch_merge_patch(remote_series, pname):
     """Merge a patch from a remote branch into the current tree.
     """
     patch = remote_series.get_patch(pname)
-    git.merge(patch.get_bottom(), git.get_head(), patch.get_top())
+    git.merge_recursive(patch.get_bottom(), git.get_head(), patch.get_top())
 
 def __series_merge_patch(base, patchdir, pname):
     """Merge a patch file with the given StGIT patch.
@@ -68,18 +63,6 @@ def __series_merge_patch(base, patchdir, pname):
 def func(parser, options, args):
     """Synchronise a range of patches
     """
-    if options.undo:
-        if options.ref_branch or options.series:
-            raise CmdException, \
-                  '--undo cannot be specified with --ref-branch or --series'
-        __check_all()
-
-        out.start('Undoing the sync of "%s"' % crt_series.get_current())
-        crt_series.undo_refresh()
-        git.reset()
-        out.done()
-        return
-
     if options.ref_branch:
         remote_series = stack.Series(options.ref_branch)
         if options.ref_branch == crt_series.get_name():
@@ -136,15 +119,16 @@ def func(parser, options, args):
         to_pop = applied[applied.index(first_patch) + 1:]
         if to_pop:
             pop_patches(crt_series, to_pop[::-1])
-        popped = to_pop + [p for p in patches if p in unapplied]
+        pushed = [first_patch]
     else:
-        popped = patches
+        to_pop = []
+        pushed = []
+    popped = to_pop + [p for p in patches if p in unapplied]
 
-    for p in patches:
+    for p in pushed + popped:
         if p in popped:
             # push this patch
             push_patches(crt_series, [p])
-            popped.remove(p)
         if p not in sync_patches:
             # nothing to synchronise
             continue
@@ -156,9 +140,7 @@ def func(parser, options, args):
         bottom = patch.get_bottom()
         top = patch.get_top()
 
-        # reset the patch backup information. That's needed in case we
-        # undo the sync but there were no changes made
-        patch.set_bottom(bottom, backup = True)
+        # reset the patch backup information.
         patch.set_top(top, backup = True)
 
         # the actual merging (either from a branch or an external file)
@@ -172,7 +154,3 @@ def func(parser, options, args):
             out.done('updated')
         else:
             out.done()
-
-    # push the remaining patches
-    if popped:
-        push_patches(crt_series, popped)