changeset 6194:1e7190adffca

fixup: use compat.InputError for invalid user input
author Anton Shestakov <av6@dwimlabs.net>
date Sun, 06 Mar 2022 17:46:33 +0300
parents e58e4af1a730
children 9e0aa8929206
files hgext3rd/evolve/cmdrewrite.py hgext3rd/evolve/compat.py tests/test-fixup.t
diffstat 3 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/cmdrewrite.py	Mon Mar 07 13:33:57 2022 +0300
+++ b/hgext3rd/evolve/cmdrewrite.py	Sun Mar 06 17:46:33 2022 +0300
@@ -1485,9 +1485,9 @@
     abortopt = opts.get('abort')
     if node or opts.get('rev'):
         if contopt:
-            raise error.Abort(_(b'cannot specify a revision with --continue'))
+            raise compat.InputError(_(b'cannot specify a revision with --continue'))
         if abortopt:
-            raise error.Abort(_(b'cannot specify a revision with --abort'))
+            raise compat.InputError(_(b'cannot specify a revision with --abort'))
     # state file for --continue/--abort cases
     fixup_state = state.cmdstate(repo, b'fixup-state')
     if contopt:
@@ -1502,11 +1502,11 @@
         return abortfixup(ui, repo, fixup_state)
 
     if node and opts.get('rev'):
-        raise error.Abort(_(b'please specify just one revision'))
+        raise compat.InputError(_(b'please specify just one revision'))
     if not node:
         node = opts.get('rev')
     if not node:
-        raise error.Abort(_(b'please specify a revision to fixup'))
+        raise compat.InputError(_(b'please specify a revision to fixup'))
     target_ctx = scmutil.revsingle(repo, node)
 
     fixup_state[b'startnode'] = repo[b'.'].node()
--- a/hgext3rd/evolve/compat.py	Mon Mar 07 13:33:57 2022 +0300
+++ b/hgext3rd/evolve/compat.py	Sun Mar 06 17:46:33 2022 +0300
@@ -424,17 +424,12 @@
         def to_display(name):
             return pycompat.sysbytes(name).replace(b'_', b'-')
 
-        if util.safehasattr(error, 'InputError'):
-            err = error.InputError
-        else:
-            # hg <= 5.6 (8d72e29ad1e0)
-            err = error.Abort
         previous = None
         for x in args:
             if opts.get(x):
                 if previous:
-                    raise err(_(b'cannot specify both --%s and --%s')
-                              % (to_display(previous), to_display(x)))
+                    raise InputError(_(b'cannot specify both --%s and --%s')
+                                     % (to_display(previous), to_display(x)))
                 previous = x
         return previous
 
@@ -570,3 +565,9 @@
     # hg <= 5.9 (dcd97b082b3b)
     def dirchanges(dirstate):
         return [f for f in dirstate if dirstate[f] != b'n']
+
+if util.safehasattr(error, 'InputError'):
+    InputError = error.InputError
+else:
+    # hg <= 5.6 (8d72e29ad1e0)
+    InputError = error.Abort
--- a/tests/test-fixup.t	Mon Mar 07 13:33:57 2022 +0300
+++ b/tests/test-fixup.t	Sun Mar 06 17:46:33 2022 +0300
@@ -307,15 +307,15 @@
 
   $ hg fixup tip --abort
   abort: cannot specify a revision with --abort
-  [255]
+  [10]
 
   $ hg fixup -r tip --continue
   abort: cannot specify a revision with --continue
-  [255]
+  [10]
 
   $ hg fixup
   abort: please specify a revision to fixup
-  [255]
+  [10]
 
   $ hg fixup tip
   nothing changed
@@ -342,7 +342,7 @@
 
   $ hg fixup :10 -r 5
   abort: please specify just one revision
-  [255]
+  [10]
 
   $ cd ..