changeset 43899:fff21278554b

rebase: use cmdutil.check_at_most_one_arg() for action Here we also needed to know what the action was (if any), so I've updated the helper to return any specified option. Differential Revision: https://phab.mercurial-scm.org/D7640
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 12 Dec 2019 15:55:33 -0800
parents 023ad45e2fd2
children 3b50de911200
files hgext/rebase.py mercurial/cmdutil.py tests/test-rebase-obsolete.t tests/test-rebase-parameters.t
diffstat 4 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Thu Dec 12 22:30:59 2019 -0800
+++ b/hgext/rebase.py	Thu Dec 12 15:55:33 2019 -0800
@@ -1021,12 +1021,7 @@
     inmemory = ui.configbool(b'rebase', b'experimental.inmemory')
     dryrun = opts.get(b'dry_run')
     confirm = opts.get(b'confirm')
-    selactions = [k for k in [b'abort', b'stop', b'continue'] if opts.get(k)]
-    if len(selactions) > 1:
-        raise error.Abort(
-            _(b'cannot use --%s with --%s') % tuple(selactions[:2])
-        )
-    action = selactions[0] if selactions else None
+    action = cmdutil.check_at_most_one_arg(opts, b'abort', b'stop', b'continue')
     if dryrun and action:
         raise error.Abort(_(b'cannot specify both --dry-run and --%s') % action)
     if confirm and action:
--- a/mercurial/cmdutil.py	Thu Dec 12 22:30:59 2019 -0800
+++ b/mercurial/cmdutil.py	Thu Dec 12 15:55:33 2019 -0800
@@ -261,7 +261,10 @@
 
 
 def check_at_most_one_arg(opts, *args):
-    """abort if more than one of the arguments are in opts"""
+    """abort if more than one of the arguments are in opts
+
+    Returns the unique argument or None if none of them were specified.
+    """
     previous = None
     for x in args:
         if opts.get(x):
@@ -270,6 +273,7 @@
                     _(b'cannot specify both --%s and --%s') % (previous, x)
                 )
             previous = x
+    return previous
 
 
 def check_incompatible_arguments(opts, first, *others):
--- a/tests/test-rebase-obsolete.t	Thu Dec 12 22:30:59 2019 -0800
+++ b/tests/test-rebase-obsolete.t	Thu Dec 12 15:55:33 2019 -0800
@@ -2062,7 +2062,7 @@
   (use 'hg rebase --continue' or 'hg rebase --abort')
   [255]
   $ hg rebase --stop --continue
-  abort: cannot use --stop with --continue
+  abort: cannot specify both --stop and --continue
   [255]
 
 Test --stop moves bookmarks of original revisions to new rebased nodes:
--- a/tests/test-rebase-parameters.t	Thu Dec 12 22:30:59 2019 -0800
+++ b/tests/test-rebase-parameters.t	Thu Dec 12 15:55:33 2019 -0800
@@ -61,7 +61,7 @@
   [1]
 
   $ hg rebase --continue --abort
-  abort: cannot use --abort with --continue
+  abort: cannot specify both --abort and --continue
   [255]
 
   $ hg rebase --continue --collapse