import: leverage cmdutil.check_incompatible_arguments()
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 15 Oct 2020 21:48:43 -0700
changeset 45740 d1cabce5ef05
parent 45739 693da1b928af
child 45741 4f7309fdfb60
import: leverage cmdutil.check_incompatible_arguments() Differential Revision: https://phab.mercurial-scm.org/D9217
mercurial/commands.py
tests/test-import-bypass.t
tests/test-import.t
--- a/mercurial/commands.py	Thu Oct 15 21:44:03 2020 -0700
+++ b/mercurial/commands.py	Thu Oct 15 21:48:43 2020 -0700
@@ -4041,6 +4041,10 @@
     Returns 0 on success, 1 on partial success (see --partial).
     """
 
+    cmdutil.check_incompatible_arguments(
+        opts, 'no_commit', ['bypass', 'secret']
+    )
+    cmdutil.check_incompatible_arguments(opts, 'exact', ['edit', 'prefix'])
     opts = pycompat.byteskwargs(opts)
     if not patch1:
         raise error.Abort(_(b'need at least one patch to import'))
@@ -4053,10 +4057,6 @@
 
     exact = opts.get(b'exact')
     update = not opts.get(b'bypass')
-    if not update and opts.get(b'no_commit'):
-        raise error.Abort(_(b'cannot use --no-commit with --bypass'))
-    if opts.get(b'secret') and opts.get(b'no_commit'):
-        raise error.Abort(_(b'cannot use --no-commit with --secret'))
     try:
         sim = float(opts.get(b'similarity') or 0)
     except ValueError:
@@ -4065,11 +4065,6 @@
         raise error.Abort(_(b'similarity must be between 0 and 100'))
     if sim and not update:
         raise error.Abort(_(b'cannot use --similarity with --bypass'))
-    if exact:
-        if opts.get(b'edit'):
-            raise error.Abort(_(b'cannot use --exact with --edit'))
-        if opts.get(b'prefix'):
-            raise error.Abort(_(b'cannot use --exact with --prefix'))
 
     base = opts[b"base"]
     msgs = []
--- a/tests/test-import-bypass.t	Thu Oct 15 21:44:03 2020 -0700
+++ b/tests/test-import-bypass.t	Thu Oct 15 21:48:43 2020 -0700
@@ -26,7 +26,7 @@
 and '--edit')
 
   $ hg import --bypass --exact --edit ../test.diff
-  abort: cannot use --exact with --edit
+  abort: cannot specify both --exact and --edit
   [255]
   $ hg import --bypass --exact ../test.diff
   applying ../test.diff
@@ -188,13 +188,13 @@
 Test unsupported combinations
 
   $ hg import --bypass --no-commit ../test.diff
-  abort: cannot use --no-commit with --bypass
+  abort: cannot specify both --no-commit and --bypass
   [255]
   $ hg import --bypass --similarity 50 ../test.diff
   abort: cannot use --similarity with --bypass
   [255]
   $ hg import --exact --prefix dir/ ../test.diff
-  abort: cannot use --exact with --prefix
+  abort: cannot specify both --exact and --prefix
   [255]
 
 Test commit editor
--- a/tests/test-import.t	Thu Oct 15 21:44:03 2020 -0700
+++ b/tests/test-import.t	Thu Oct 15 21:48:43 2020 -0700
@@ -444,7 +444,7 @@
 
   $ hg clone -r0 a b -q
   $ hg --cwd b import --no-commit --secret ../exported-tip.patch
-  abort: cannot use --no-commit with --secret
+  abort: cannot specify both --no-commit and --secret
   [255]
   $ hg --cwd b import --secret ../exported-tip.patch
   applying ../exported-tip.patch