changeset 48054:f27a83399abb

histedit: use more specific exceptions for more detailed exit codes Differential Revision: https://phab.mercurial-scm.org/D11509
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 28 Sep 2021 09:32:24 -0700
parents 6256c7525222
children 84e7a86e3a63
files hgext/histedit.py tests/test-histedit-arguments.t tests/test-histedit-edit.t tests/test-histedit-non-commute-abort.t tests/test-histedit-obsolete.t tests/test-histedit-outgoing.t
diffstat 6 files changed, 30 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Tue Sep 28 09:25:05 2021 -0700
+++ b/hgext/histedit.py	Tue Sep 28 09:32:24 2021 -0700
@@ -749,7 +749,7 @@
 
 
 def abortdirty():
-    raise error.Abort(
+    raise error.StateError(
         _(b'working copy has pending changes'),
         hint=_(
             b'amend, commit, or revert them and run histedit '
@@ -1052,12 +1052,12 @@
 
     outgoing = discovery.findcommonoutgoing(repo, other, revs, force=force)
     if not outgoing.missing:
-        raise error.Abort(_(b'no outgoing ancestors'))
+        raise error.StateError(_(b'no outgoing ancestors'))
     roots = list(repo.revs(b"roots(%ln)", outgoing.missing))
     if len(roots) > 1:
         msg = _(b'there are ambiguous outgoing revisions')
         hint = _(b"see 'hg help histedit' for more detail")
-        raise error.Abort(msg, hint=hint)
+        raise error.StateError(msg, hint=hint)
     return repo[roots[0]].node()
 
 
@@ -1703,13 +1703,13 @@
             if defaultrev is not None:
                 revs.append(defaultrev)
         if len(revs) != 1:
-            raise error.Abort(
+            raise error.InputError(
                 _(b'histedit requires exactly one ancestor revision')
             )
 
         rr = list(repo.set(b'roots(%ld)', scmutil.revrange(repo, revs)))
         if len(rr) != 1:
-            raise error.Abort(
+            raise error.InputError(
                 _(
                     b'The specified revisions must have '
                     b'exactly one common root'
@@ -1720,7 +1720,7 @@
         topmost = repo.dirstate.p1()
         revs = between(repo, root, topmost, keep)
         if not revs:
-            raise error.Abort(
+            raise error.InputError(
                 _(b'%s is not an ancestor of working directory') % short(root)
             )
 
@@ -1926,7 +1926,7 @@
     # blanket if mq patches are applied somewhere
     mq = getattr(repo, 'mq', None)
     if mq and mq.applied:
-        raise error.Abort(_(b'source has mq patches applied'))
+        raise error.StateError(_(b'source has mq patches applied'))
 
     # basic argument incompatibility processing
     outg = opts.get(b'outgoing')
@@ -1934,24 +1934,26 @@
     abort = opts.get(b'abort')
     force = opts.get(b'force')
     if force and not outg:
-        raise error.Abort(_(b'--force only allowed with --outgoing'))
+        raise error.InputError(_(b'--force only allowed with --outgoing'))
     if goal == b'continue':
         if any((outg, abort, revs, freeargs, rules, editplan)):
-            raise error.Abort(_(b'no arguments allowed with --continue'))
+            raise error.InputError(_(b'no arguments allowed with --continue'))
     elif goal == b'abort':
         if any((outg, revs, freeargs, rules, editplan)):
-            raise error.Abort(_(b'no arguments allowed with --abort'))
+            raise error.InputError(_(b'no arguments allowed with --abort'))
     elif goal == b'edit-plan':
         if any((outg, revs, freeargs)):
-            raise error.Abort(
+            raise error.InputError(
                 _(b'only --commands argument allowed with --edit-plan')
             )
     else:
         if outg:
             if revs:
-                raise error.Abort(_(b'no revisions allowed with --outgoing'))
+                raise error.InputError(
+                    _(b'no revisions allowed with --outgoing')
+                )
             if len(freeargs) > 1:
-                raise error.Abort(
+                raise error.InputError(
                     _(b'only one repo argument allowed with --outgoing')
                 )
         else:
@@ -1962,7 +1964,7 @@
                     revs.append(defaultrev)
 
             if len(revs) != 1:
-                raise error.Abort(
+                raise error.InputError(
                     _(b'histedit requires exactly one ancestor revision')
                 )
 
@@ -1995,7 +1997,7 @@
             ),
             default=1,
         ):
-            raise error.Abort(_(b'histedit cancelled\n'))
+            raise error.CanceledError(_(b'histedit cancelled\n'))
     # rebuild state
     if goal == goalcontinue:
         state.read()
@@ -2205,7 +2207,7 @@
     else:
         rr = list(repo.set(b'roots(%ld)', scmutil.revrange(repo, revs)))
         if len(rr) != 1:
-            raise error.Abort(
+            raise error.InputError(
                 _(
                     b'The specified revisions must have '
                     b'exactly one common root'
@@ -2215,7 +2217,7 @@
 
     revs = between(repo, root, topmost, state.keep)
     if not revs:
-        raise error.Abort(
+        raise error.InputError(
             _(b'%s is not an ancestor of working directory') % short(root)
         )
 
@@ -2245,7 +2247,7 @@
                 followcopies=False,
             )
         except error.Abort:
-            raise error.Abort(
+            raise error.StateError(
                 _(
                     b"untracked files in working directory conflict with files in %s"
                 )
@@ -2323,7 +2325,9 @@
     if revs and not keep:
         rewriteutil.precheck(repo, revs, b'edit')
         if repo.revs(b'(%ld) and merge()', revs):
-            raise error.Abort(_(b'cannot edit history that contains merges'))
+            raise error.StateError(
+                _(b'cannot edit history that contains merges')
+            )
     return pycompat.maplist(repo.changelog.node, revs)
 
 
--- a/tests/test-histedit-arguments.t	Tue Sep 28 09:25:05 2021 -0700
+++ b/tests/test-histedit-arguments.t	Tue Sep 28 09:32:24 2021 -0700
@@ -93,7 +93,7 @@
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg histedit -r 4
   abort: 08d98a8350f3 is not an ancestor of working directory
-  [255]
+  [10]
   $ hg up --quiet
 
 
@@ -290,7 +290,7 @@
   created new head
   $ hg histedit -r 'heads(all())'
   abort: The specified revisions must have exactly one common root
-  [255]
+  [10]
 
 Test that trimming description using multi-byte characters
 --------------------------------------------------------------------
--- a/tests/test-histedit-edit.t	Tue Sep 28 09:25:05 2021 -0700
+++ b/tests/test-histedit-edit.t	Tue Sep 28 09:32:24 2021 -0700
@@ -552,5 +552,5 @@
   do you want to continue (yN)?  n
   abort: histedit cancelled
   
-  [255]
+  [250]
   $ cd ..
--- a/tests/test-histedit-non-commute-abort.t	Tue Sep 28 09:25:05 2021 -0700
+++ b/tests/test-histedit-non-commute-abort.t	Tue Sep 28 09:32:24 2021 -0700
@@ -160,7 +160,7 @@
   $ hg histedit e860deea161a
   c: untracked file differs
   abort: untracked files in working directory conflict with files in 055a42cdd887
-  [255]
+  [20]
 
 We should have detected the collision early enough we're not in a
 histedit state, and p1 is unchanged.
--- a/tests/test-histedit-obsolete.t	Tue Sep 28 09:25:05 2021 -0700
+++ b/tests/test-histedit-obsolete.t	Tue Sep 28 09:32:24 2021 -0700
@@ -508,7 +508,7 @@
   $ hg ci -m 'modify wat'
   $ hg histedit 050280826e04
   abort: cannot edit history that contains merges
-  [255]
+  [20]
   $ cd ..
 
 Check abort behavior
--- a/tests/test-histedit-outgoing.t	Tue Sep 28 09:25:05 2021 -0700
+++ b/tests/test-histedit-outgoing.t	Tue Sep 28 09:32:24 2021 -0700
@@ -134,7 +134,7 @@
   $ HGEDITOR=cat hg -q histedit --outgoing '../r'
   abort: there are ambiguous outgoing revisions
   (see 'hg help histedit' for more detail)
-  [255]
+  [20]
 
   $ hg -q update -C 2
   $ echo aa >> a
@@ -151,6 +151,6 @@
   $ HGEDITOR=cat hg -q histedit --outgoing '../r#default'
   abort: there are ambiguous outgoing revisions
   (see 'hg help histedit' for more detail)
-  [255]
+  [20]
 
   $ cd ..