Patchwork D9914: errors: use more specific errors in rebase extension

login
register
mail settings
Submitter phabricator
Date Jan. 30, 2021, 12:38 a.m.
Message ID <differential-rev-PHID-DREV-lwbubnjng7xt7djn2opu-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48224/
State Superseded
Headers show

Comments

phabricator - Jan. 30, 2021, 12:38 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9914

AFFECTED FILES
  hgext/rebase.py
  tests/test-rebase-collapse.t
  tests/test-rebase-dest.t
  tests/test-rebase-mq.t
  tests/test-rebase-named-branches.t
  tests/test-rebase-newancestor.t
  tests/test-rebase-obsolete.t
  tests/test-rebase-parameters.t
  tests/test-rebase-scenario-global.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-rebase-scenario-global.t b/tests/test-rebase-scenario-global.t
--- a/tests/test-rebase-scenario-global.t
+++ b/tests/test-rebase-scenario-global.t
@@ -266,14 +266,14 @@ 
 
   $ hg rebase -s 5 -d 6
   abort: source and destination form a cycle
-  [255]
+  [10]
 
 G onto B - merge revision with both parents not in ancestors of target:
 
   $ hg rebase -s 6 -d 1
   rebasing 6:eea13746799a "G"
   abort: cannot rebase 6:eea13746799a without moving at least one of its parents
-  [255]
+  [10]
   $ hg rebase --abort
   rebase aborted
 
diff --git a/tests/test-rebase-parameters.t b/tests/test-rebase-parameters.t
--- a/tests/test-rebase-parameters.t
+++ b/tests/test-rebase-parameters.t
@@ -66,7 +66,7 @@ 
 
   $ hg rebase --continue --collapse
   abort: cannot use collapse with continue or abort
-  [255]
+  [10]
 
   $ hg rebase --continue --dest 4
   abort: cannot specify both --continue and --dest
@@ -94,15 +94,15 @@ 
 
   $ hg rebase --rev 'wdir()' --dest 6
   abort: cannot rebase the working copy
-  [255]
+  [10]
 
   $ hg rebase --source 'wdir()' --dest 6
   abort: cannot rebase the working copy
-  [255]
+  [10]
 
   $ hg rebase --source 1 --source 'wdir()' --dest 6
   abort: cannot rebase the working copy
-  [255]
+  [10]
 
   $ hg rebase --source '1 & !1' --dest 8
   empty "source" revision set - nothing to rebase
@@ -508,11 +508,11 @@ 
 
   $ hg rebase -i
   abort: interactive history editing is supported by the 'histedit' extension (see "hg --config extensions.histedit= help -e histedit")
-  [255]
+  [10]
 
   $ hg rebase --interactive
   abort: interactive history editing is supported by the 'histedit' extension (see "hg --config extensions.histedit= help -e histedit")
-  [255]
+  [10]
 
   $ cd ..
 
diff --git a/tests/test-rebase-obsolete.t b/tests/test-rebase-obsolete.t
--- a/tests/test-rebase-obsolete.t
+++ b/tests/test-rebase-obsolete.t
@@ -560,7 +560,7 @@ 
   rebasing 2:b18e25de2cf5 D "D"
   rebasing 6:f15c3adaf214 F tip "F"
   abort: cannot rebase 6:f15c3adaf214 without moving at least one of its parents
-  [255]
+  [10]
 
   $ cd ..
 
@@ -948,7 +948,7 @@ 
   $ hg rebase -s 10 -d 12
   abort: this rebase will cause divergences from: 121d9e3bc4c6
   (to force the rebase please set experimental.evolution.allowdivergence=True)
-  [255]
+  [10]
   $ hg log -G
   @  14:73568ab6879d bar foo
   |
@@ -1152,7 +1152,7 @@ 
   $ hg rebase -r 'c'::'f' -d 'x'
   abort: this rebase will cause divergences from: 76be324c128b
   (to force the rebase please set experimental.evolution.allowdivergence=True)
-  [255]
+  [10]
   $ hg rebase --config experimental.evolution.allowdivergence=true -r 'c'::'f' -d 'x'
   rebasing 3:a82ac2b38757 c "c"
   rebasing 4:76be324c128b d "d"
@@ -1566,7 +1566,7 @@ 
   $ hg rebase -b 'desc("D")' -d 'desc("J")'
   abort: this rebase will cause divergences from: 112478962961
   (to force the rebase please set experimental.evolution.allowdivergence=True)
-  [255]
+  [10]
 
 Rebase merge where both parents have successors in destination
 
@@ -1585,7 +1585,7 @@ 
   note: not rebasing 5:b23a2cc00842 B "B", already in destination as 1:058c1e1fb10a D "D"
   rebasing 7:dac5d11c5a7d E tip "E"
   abort: rebasing 7:dac5d11c5a7d will include unwanted changes from 3:59c792af609c, 5:b23a2cc00842 or 2:ba2b7fa7166d, 4:a3d17304151f
-  [255]
+  [10]
   $ cd ..
 
 Rebase a non-clean merge. One parent has successor in destination, the other
@@ -1941,7 +1941,7 @@ 
   $ hg rebase --stop
   abort: cannot remove original changesets with unrebased descendants
   (either enable obsmarkers to allow unstable revisions or use --keep to keep original changesets)
-  [255]
+  [20]
   $ hg rebase --abort
   saved backup bundle to $TESTTMP/rbstop/.hg/strip-backup/b15528633407-6eb72b6f-backup.hg
   rebase aborted
@@ -2020,7 +2020,7 @@ 
   [240]
   $ hg rebase --stop
   abort: cannot stop in --collapse session
-  [255]
+  [20]
   $ hg rebase --abort
   rebase aborted
   $ hg diff
diff --git a/tests/test-rebase-newancestor.t b/tests/test-rebase-newancestor.t
--- a/tests/test-rebase-newancestor.t
+++ b/tests/test-rebase-newancestor.t
@@ -154,7 +154,7 @@ 
   rebasing 2:ec2c14fb2984 "dev: f-dev stuff"
   rebasing 4:4b019212aaf6 "dev: merge default"
   abort: rebasing 4:4b019212aaf6 will include unwanted changes from 1:1d1a643d390e
-  [255]
+  [10]
   $ cd ..
 
 
@@ -314,7 +314,7 @@ 
   rebasing 6:b296604d9846 E "E"
   rebasing 7:caa9781e507d F tip "F"
   abort: rebasing 7:caa9781e507d will include unwanted changes from 4:d6003a550c2c or 3:c1e6b162678d
-  [255]
+  [10]
 
 The warning does not get printed if there is no unwanted change detected:
 
diff --git a/tests/test-rebase-named-branches.t b/tests/test-rebase-named-branches.t
--- a/tests/test-rebase-named-branches.t
+++ b/tests/test-rebase-named-branches.t
@@ -247,7 +247,7 @@ 
   
   $ hg rebase -s 5 -d 6
   abort: source and destination form a cycle
-  [255]
+  [10]
 
   $ hg rebase -s 6 -d 5
   rebasing 6:3944801ae4ea "dev-two named branch"
diff --git a/tests/test-rebase-mq.t b/tests/test-rebase-mq.t
--- a/tests/test-rebase-mq.t
+++ b/tests/test-rebase-mq.t
@@ -46,14 +46,14 @@ 
 
   $ hg rebase -s 1 -d 3
   abort: cannot rebase onto an applied mq patch
-  [255]
+  [20]
 
 Rebase - same thing, but mq patch is default dest:
 
   $ hg up -q 1
   $ hg rebase
   abort: cannot rebase onto an applied mq patch
-  [255]
+  [20]
   $ hg up -q qtip
 
 Rebase - generate a conflict:
diff --git a/tests/test-rebase-dest.t b/tests/test-rebase-dest.t
--- a/tests/test-rebase-dest.t
+++ b/tests/test-rebase-dest.t
@@ -18,7 +18,7 @@ 
   $ hg rebase
   abort: you must specify a destination
   (use: hg rebase -d REV)
-  [255]
+  [10]
   $ hg rebase -d 1
   rebasing 2:5db65b93a12b tip "cc"
   saved backup bundle to $TESTTMP/repo/.hg/strip-backup/5db65b93a12b-4fb789ec-rebase.hg
@@ -74,7 +74,7 @@ 
   $ hg pull --rebase
   abort: rebase destination required by configuration
   (use hg pull followed by hg rebase -d DEST)
-  [255]
+  [10]
 
 Setup rebase with multiple destinations
 
@@ -152,7 +152,7 @@ 
   > A D
   > EOS
   abort: --collapse does not work with multiple destinations
-  [255]
+  [10]
 
 Multiple destinations cannot be used with --base:
 
@@ -192,7 +192,7 @@ 
   > Z
   > EOS
   abort: rebase destination for f0a671a46792 is not unique
-  [255]
+  [10]
 
 Destination is an ancestor of source:
 
@@ -204,7 +204,7 @@ 
   > Z
   > EOS
   abort: source and destination form a cycle
-  [255]
+  [10]
 
 BUG: cycles aren't flagged correctly when --dry-run is set:
   $ rebasewithdag -s B -d 'SRC' --dry-run <<'EOS'
@@ -216,7 +216,7 @@ 
   > EOS
   abort: source and destination form a cycle
   starting dry-run rebase; repository will not be changed
-  [255]
+  [10]
 
 Switch roots:
 
@@ -329,7 +329,7 @@ 
   >   Z
   > EOS
   abort: source and destination form a cycle
-  [255]
+  [10]
 
 Detect source is ancestor of dest in runtime:
 
@@ -341,7 +341,7 @@ 
   >   A
   > EOS
   abort: source is ancestor of destination
-  [255]
+  [10]
 
 "Already rebased" fast path still works:
 
diff --git a/tests/test-rebase-collapse.t b/tests/test-rebase-collapse.t
--- a/tests/test-rebase-collapse.t
+++ b/tests/test-rebase-collapse.t
@@ -134,7 +134,7 @@ 
 
   $ hg rebase --base B -m 'custom message'
   abort: message can only be specified with collapse
-  [255]
+  [10]
 
   $ cat > $TESTTMP/checkeditform.sh <<EOF
   > env | grep HGEDITFORM
@@ -180,7 +180,7 @@ 
 
   $ hg rebase -s C --dest H --collapse
   abort: unable to collapse on top of 3, there is more than one external parent: 1, 6
-  [255]
+  [10]
 
 Rebase and collapse - E onto H:
 
@@ -386,7 +386,7 @@ 
 BROKEN: should be allowed
   $ hg rebase --collapse -r 'B+D+F' -d G
   abort: unable to collapse on top of 2, there is more than one external parent: 3, 5
-  [255]
+  [10]
   $ cd ..
 
 
@@ -404,7 +404,7 @@ 
 
   $ hg rebase --collapse -d H -s 'B+F'
   abort: unable to collapse on top of 5, there is more than one external parent: 1, 3
-  [255]
+  [10]
   $ cd ..
 
 With internal merge:
@@ -484,7 +484,7 @@ 
   
   $ hg rebase --keepbranches --collapse -s 1 -d 3
   abort: cannot collapse multiple named branches
-  [255]
+  [10]
 
   $ cd ..
 
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -144,7 +144,7 @@ 
         return smartset.baseset()
     dests = destutil.orphanpossibledestination(repo, src)
     if len(dests) > 1:
-        raise error.Abort(
+        raise error.InputError(
             _(b"ambiguous automatic rebase: %r could end up on any of %r")
             % (src, dests)
         )
@@ -424,7 +424,7 @@ 
         if self.collapsef:
             dests = set(self.destmap.values())
             if len(dests) != 1:
-                raise error.Abort(
+                raise error.InputError(
                     _(b'--collapse does not work with multiple destinations')
                 )
             destrev = next(iter(dests))
@@ -469,7 +469,7 @@ 
                 for rev in self.state:
                     branches.add(repo[rev].branch())
                     if len(branches) > 1:
-                        raise error.Abort(
+                        raise error.InputError(
                             _(b'cannot collapse multiple named branches')
                         )
 
@@ -1093,10 +1093,10 @@ 
         with repo.wlock(), repo.lock():
             rbsrt.restorestatus()
             if rbsrt.collapsef:
-                raise error.Abort(_(b"cannot stop in --collapse session"))
+                raise error.StateError(_(b"cannot stop in --collapse session"))
             allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt)
             if not (rbsrt.keepf or allowunstable):
-                raise error.Abort(
+                raise error.StateError(
                     _(
                         b"cannot remove original changesets with"
                         b" unrebased descendants"
@@ -1220,14 +1220,16 @@ 
                 )
                 % help
             )
-            raise error.Abort(msg)
+            raise error.InputError(msg)
 
         if rbsrt.collapsemsg and not rbsrt.collapsef:
-            raise error.Abort(_(b'message can only be specified with collapse'))
+            raise error.InputError(
+                _(b'message can only be specified with collapse')
+            )
 
         if action:
             if rbsrt.collapsef:
-                raise error.Abort(
+                raise error.InputError(
                     _(b'cannot use collapse with continue or abort')
                 )
             if action == b'abort' and opts.get(b'tool', False):
@@ -1294,7 +1296,7 @@ 
         cmdutil.bailifchanged(repo)
 
     if ui.configbool(b'commands', b'rebase.requiredest') and not destf:
-        raise error.Abort(
+        raise error.InputError(
             _(b'you must specify a destination'),
             hint=_(b'use: hg rebase -d REV'),
         )
@@ -1388,7 +1390,7 @@ 
             return None
 
     if wdirrev in rebaseset:
-        raise error.Abort(_(b'cannot rebase the working copy'))
+        raise error.InputError(_(b'cannot rebase the working copy'))
     rebasingwcp = repo[b'.'].rev() in rebaseset
     ui.log(
         b"rebase",
@@ -1426,7 +1428,7 @@ 
                 elif size == 0:
                     ui.note(_(b'skipping %s - empty destination\n') % repo[r])
                 else:
-                    raise error.Abort(
+                    raise error.InputError(
                         _(b'rebase destination for %s is not unique') % repo[r]
                     )
 
@@ -1459,7 +1461,7 @@ 
         return nullrev
     if len(parents) == 1:
         return parents.pop()
-    raise error.Abort(
+    raise error.InputError(
         _(
             b'unable to collapse on top of %d, there is more '
             b'than one external parent: %s'
@@ -1659,7 +1661,7 @@ 
             b"to force the rebase please set "
             b"experimental.evolution.allowdivergence=True"
         )
-        raise error.Abort(msg % (b",".join(divhashes),), hint=h)
+        raise error.InputError(msg % (b",".join(divhashes),), hint=h)
 
 
 def successorrevs(unfi, rev):
@@ -1762,7 +1764,7 @@ 
         #    /|    # None of A and B will be changed to D and rebase fails.
         #   A B D
         if set(newps) == set(oldps) and dest not in newps:
-            raise error.Abort(
+            raise error.InputError(
                 _(
                     b'cannot rebase %d:%s without '
                     b'moving at least one of its parents'
@@ -1774,7 +1776,7 @@ 
     # impossible. With multi-dest, the initial check does not cover complex
     # cases since we don't have abstractions to dry-run rebase cheaply.
     if any(p != nullrev and isancestor(rev, p) for p in newps):
-        raise error.Abort(_(b'source is ancestor of destination'))
+        raise error.InputError(_(b'source is ancestor of destination'))
 
     # Check if the merge will contain unwanted changes. That may happen if
     # there are multiple special (non-changelog ancestor) merge bases, which
@@ -1836,7 +1838,7 @@ 
                         if revs is not None
                     )
                 )
-                raise error.Abort(
+                raise error.InputError(
                     _(b'rebasing %d:%s will include unwanted changes from %s')
                     % (rev, repo[rev], unwanteddesc)
                 )
@@ -1981,7 +1983,7 @@ 
             if destmap[r] not in srcset:
                 result.append(r)
         if not result:
-            raise error.Abort(_(b'source and destination form a cycle'))
+            raise error.InputError(_(b'source and destination form a cycle'))
         srcset -= set(result)
         yield result
 
@@ -2001,12 +2003,12 @@ 
     if b'qtip' in repo.tags():
         mqapplied = {repo[s.node].rev() for s in repo.mq.applied}
         if set(destmap.values()) & mqapplied:
-            raise error.Abort(_(b'cannot rebase onto an applied mq patch'))
+            raise error.StateError(_(b'cannot rebase onto an applied mq patch'))
 
     # Get "cycle" error early by exhausting the generator.
     sortedsrc = list(sortsource(destmap))  # a list of sorted revs
     if not sortedsrc:
-        raise error.Abort(_(b'no matching revisions'))
+        raise error.InputError(_(b'no matching revisions'))
 
     # Only check the first batch of revisions to rebase not depending on other
     # rebaseset. This means "source is ancestor of destination" for the second
@@ -2014,7 +2016,7 @@ 
     # "defineparents" to do that check.
     roots = list(repo.set(b'roots(%ld)', sortedsrc[0]))
     if not roots:
-        raise error.Abort(_(b'no matching revisions'))
+        raise error.InputError(_(b'no matching revisions'))
 
     def revof(r):
         return r.rev()
@@ -2026,7 +2028,7 @@ 
         dest = repo[destmap[root.rev()]]
         commonbase = root.ancestor(dest)
         if commonbase == root:
-            raise error.Abort(_(b'source is ancestor of destination'))
+            raise error.InputError(_(b'source is ancestor of destination'))
         if commonbase == dest:
             wctx = repo[None]
             if dest == wctx.p1():
@@ -2119,7 +2121,7 @@ 
         if ui.configbool(b'commands', b'rebase.requiredest'):
             msg = _(b'rebase destination required by configuration')
             hint = _(b'use hg pull followed by hg rebase -d DEST')
-            raise error.Abort(msg, hint=hint)
+            raise error.InputError(msg, hint=hint)
 
         with repo.wlock(), repo.lock():
             if opts.get('update'):
@@ -2176,7 +2178,7 @@ 
                         commands.update(ui, repo)
     else:
         if opts.get('tool'):
-            raise error.Abort(_(b'--tool can only be used with --rebase'))
+            raise error.InputError(_(b'--tool can only be used with --rebase'))
         ret = orig(ui, repo, *args, **opts)
 
     return ret