# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 2021-05-04 17:49:32
# Node ID d90f6237b3aacb93548d24bb38a31d41de01e22d
# Parent  5b6dd0d9171bba8acea58234b531bad5f21bd415

rewriteutil: say how many commits would become orphan if commit is rewritten

This copies the message from the evolve extension, but modifies it a
bit to work with the grammar (in particular with the use of "change
branch of" as `action`). I don't know why it doesn't use the same
`_formatrevs()` as for public commmits.

Differential Revision: https://phab.mercurial-scm.org/D10671

diff --git a/mercurial/rewriteutil.py b/mercurial/rewriteutil.py
--- a/mercurial/rewriteutil.py
+++ b/mercurial/rewriteutil.py
@@ -80,7 +80,9 @@ def precheck(repo, revs, action=b'rewrit
     if newunstable:
         hint = _(b"see 'hg help evolution.instability'")
         raise error.InputError(
-            _(b"cannot %s changeset with children") % action, hint=hint
+            _(b"cannot %s changeset, as that will orphan %d descendants")
+            % (action, len(newunstable)),
+            hint=hint,
         )
 
     if not obsolete.isenabled(repo, obsolete.allowdivergenceopt):
diff --git a/tests/test-amend.t b/tests/test-amend.t
--- a/tests/test-amend.t
+++ b/tests/test-amend.t
@@ -196,7 +196,7 @@ Amend in the middle of a stack
   $ hg update -q B
   $ echo 2 >> B
   $ hg amend
-  abort: cannot amend changeset with children
+  abort: cannot amend changeset, as that will orphan 1 descendants
   (see 'hg help evolution.instability')
   [10]
 
diff --git a/tests/test-branch-change.t b/tests/test-branch-change.t
--- a/tests/test-branch-change.t
+++ b/tests/test-branch-change.t
@@ -57,7 +57,7 @@ Change on non-linear set of commits
 Change in middle of the stack (linear commits)
 
   $ hg branch -r 1::3 foo
-  abort: cannot change branch of changeset with children
+  abort: cannot change branch of changeset, as that will orphan 1 descendants
   (see 'hg help evolution.instability')
   [10]
 
@@ -129,7 +129,7 @@ Change branch name to an existing branch
 Changing on a branch head which is not topological head
 
   $ hg branch -r 2 stable
-  abort: cannot change branch of changeset with children
+  abort: cannot change branch of changeset, as that will orphan 2 descendants
   (see 'hg help evolution.instability')
   [10]
 
diff --git a/tests/test-fix.t b/tests/test-fix.t
--- a/tests/test-fix.t
+++ b/tests/test-fix.t
@@ -1172,7 +1172,7 @@ an orphan. We must respect experimental.
   $ printf "two\n" > foo.whole
   $ hg commit -m "second"
   $ hg --config experimental.evolution.allowunstable=False fix -r '.^'
-  abort: cannot fix changeset with children
+  abort: cannot fix changeset, as that will orphan 1 descendants
   (see 'hg help evolution.instability')
   [10]
   $ hg fix -r '.^'
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
@@ -549,7 +549,7 @@ Test collapsing a middle revision in-pla
   o  0: f447d5abf5ea 'add'
   
   $ hg rebase --collapse -r 1 -d 0
-  abort: cannot rebase changeset with children
+  abort: cannot rebase changeset, as that will orphan 1 descendants
   (see 'hg help evolution.instability')
   [10]
 
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
@@ -452,7 +452,7 @@ Source on have two descendant heads but 
   $ hg clone -q -u . ah ah1
   $ cd ah1
   $ hg rebase -r '2::8' -d 1
-  abort: cannot rebase changeset with children
+  abort: cannot rebase changeset, as that will orphan 2 descendants
   (see 'hg help evolution.instability')
   [10]
   $ hg rebase -r '2::8' -d 1 -k
@@ -498,7 +498,7 @@ Base on have one descendant heads we ask
   $ hg clone -q -u . ah ah2
   $ cd ah2
   $ hg rebase -r '3::8' -d 1
-  abort: cannot rebase changeset with children
+  abort: cannot rebase changeset, as that will orphan 2 descendants
   (see 'hg help evolution.instability')
   [10]
   $ hg rebase -r '3::8' -d 1 --keep
@@ -541,7 +541,7 @@ rebase subset
   $ hg clone -q -u . ah ah3
   $ cd ah3
   $ hg rebase -r '3::7' -d 1
-  abort: cannot rebase changeset with children
+  abort: cannot rebase changeset, as that will orphan 3 descendants
   (see 'hg help evolution.instability')
   [10]
   $ hg rebase -r '3::7' -d 1 --keep
@@ -581,7 +581,7 @@ rebase subset with multiple head
   $ hg clone -q -u . ah ah4
   $ cd ah4
   $ hg rebase -r '3::(7+5)' -d 1
-  abort: cannot rebase changeset with children
+  abort: cannot rebase changeset, as that will orphan 1 descendants
   (see 'hg help evolution.instability')
   [10]
   $ hg rebase -r '3::(7+5)' -d 1 --keep
diff --git a/tests/test-split.t b/tests/test-split.t
--- a/tests/test-split.t
+++ b/tests/test-split.t
@@ -466,7 +466,7 @@ Split a non-head without rebase
   $ cd $TESTTMP/d
 #if obsstore-off
   $ runsplit -r 1 --no-rebase
-  abort: cannot split changeset with children
+  abort: cannot split changeset, as that will orphan 3 descendants
   (see 'hg help evolution.instability')
   [10]
 #else
@@ -518,7 +518,7 @@ Split a non-head with obsoleted descenda
   $ eval `hg tags -T '{tag}={node}\n'`
   $ rm .hg/localtags
   $ hg split $B --config experimental.evolution=createmarkers
-  abort: cannot split changeset with children
+  abort: cannot split changeset, as that will orphan 4 descendants
   (see 'hg help evolution.instability')
   [10]
   $ cat > $TESTTMP/messages <<EOF
diff --git a/tests/test-unamend.t b/tests/test-unamend.t
--- a/tests/test-unamend.t
+++ b/tests/test-unamend.t
@@ -284,7 +284,7 @@ Unamending in middle of a stack
   
 
   $ hg --config experimental.evolution=createmarkers unamend
-  abort: cannot unamend changeset with children
+  abort: cannot unamend changeset, as that will orphan 3 descendants
   (see 'hg help evolution.instability')
   [10]