changeset 5581:36ccafa69095

discovery: list the new heads like core does when failing a multi-head push The message was, and still is slightly different from core (which mentions 'remote' heads). But it's probably useful to have slightly different messages so that we can easily determine the source.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 17 Sep 2020 14:11:38 -0400
parents cc0f46025c7f
children 041024be2163
files hgext3rd/topic/discovery.py tests/test-topic-push.t
diffstat 2 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/discovery.py	Fri Aug 21 18:05:37 2020 +0530
+++ b/hgext3rd/topic/discovery.py	Thu Sep 17 14:11:38 2020 -0400
@@ -10,6 +10,7 @@
     error,
     exchange,
     extensions,
+    scmutil,
     util,
 )
 from . import (
@@ -186,7 +187,7 @@
             continue
         oldheads = [repo[n].rev() for n in b[1]]
         newheads = _filter_obsolete_heads(repo, oldheads)
-        data[b[0]] = len(newheads)
+        data[b[0]] = newheads
     return data
 
 def handlecheckheads(orig, op, inpart):
@@ -211,14 +212,24 @@
             repo.invalidatecaches()
             finalheads = _nbheads(repo)
             for branch, oldnb in tr._prepushheads.items():
-                newnb = finalheads.pop(branch, 0)
-                if oldnb < newnb:
-                    msg = _(b"push creates a new head on branch '%s'" % branch)
+                newheads = finalheads.pop(branch, [])
+                if len(oldnb) < len(newheads):
+                    cl = repo.changelog
+                    newheads = sorted(set(newheads).difference(oldnb))
+                    heads = scmutil.nodesummaries(repo, [cl.node(r) for r in newheads])
+                    msg = _(
+                        b"push creates new heads on branch '%s': %s"
+                        % (branch, heads)
+                    )
                     raise error.Abort(msg)
             for branch, newnb in finalheads.items():
-                if 1 < newnb:
-                    msg = _(b"push creates new branch '%s' with multiple heads"
-                            % branch)
+                if 1 < len(newnb):
+                    cl = repo.changelog
+                    heads = scmutil.nodesummaries(repo, [cl.node(r) for r in newnb])
+                    msg = _(
+                        b"push creates new branch '%s' with multiple heads: %s"
+                        % (branch, heads)
+                    )
                     hint = _(b"merge or see 'hg help push' for details about "
                              b"pushing new heads")
                     raise error.Abort(msg, hint=hint)
--- a/tests/test-topic-push.t	Fri Aug 21 18:05:37 2020 +0530
+++ b/tests/test-topic-push.t	Thu Sep 17 14:11:38 2020 -0400
@@ -508,5 +508,5 @@
   pushing to repoB
   searching for changes
   no changes found
-  abort: push creates a new head on branch 'default'
+  abort: push creates new heads on branch 'default': bbd9d6199b88
   [255]