[PATCH 2 of 2 Version 2] discovery: list new remote heads in prepush() on --debug

Adrian Buehlmann adrian at cadifra.com
Thu Nov 11 15:15:33 CST 2010


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1289487080 -3600
# Node ID ab1b5354c4f2298f5f29579f385cdf86b083caff
# Parent  6101a7c2efd2c03762d65eb8219fcca83be36195
discovery: list new remote heads in prepush() on --debug

With this patch applied, Mercurial will list the hashes of new remote heads
if push --debug aborts because of new remote heads (option -f/--force not set).

Example:

  $ hg push --debug repo1
  using http://example.org/repo1
  http auth: user johndoe, password not set
  sending between command
  pushing to http://example.org/repo1
  sending capabilities command
  capabilities: changegroupsubset stream=1 lookup pushkey unbundle=HG10GZ,HG10BZ,HG10UN branchmap
  sending heads command
  searching for changes
  common changesets up to 609edbc7853f
  sending branchmap command
  new remote heads on branch 'default'        <- new output line
  new remote head 5862c07f53a2                <- new output line
  abort: push creates new remote heads on branch 'default'!
  (did you forget to merge? use push -f to force)

Compare to without --debug (not changed by this patch, including it here
for reference purposes only):

  $ hg push repo1
  pushing to http://example.org/repo1
  searching for changes
  abort: push creates new remote heads on branch 'default'!
  (did you forget to merge? use push -f to force)

Motivation for this change:

'hg outgoing' may list a whole lot of benign changesets plus an odd changeset
that will trigger the "new remote heads" abort. It can be hard to spot that
single unwanted changeset (it may be an old forgotten experiment, lingering
in the local repo).

"hg log -r 'heads(outgoing())'" might be useful, but that also lists a head
that may be benign on push.

Inside prepush(), we already know which heads are causing troubles on 'hg push'.
Why not make that info available (at least on --debug)?

This would also be helpful for doing remote support, as the supporter can ask
the user to paste the output of 'hg push --debug' on error and then ask further
questions about the heads listed.

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -278,20 +278,30 @@ def prepush(repo, remote, force, revs, n
 
         # 5. Check for new heads.
         # If there are more heads after the push than before, a suitable
-        # warning, depending on unsynced status, is displayed.
+        # error message, depending on unsynced status, is displayed.
+        error = None
         for branch in branches:
-            if len(newmap[branch]) > len(oldmap[branch]):
+            newhs = set(newmap[branch])
+            oldhs = set(oldmap[branch])
+            if len(newhs) > len(oldhs):
+                if error is None:
+                    if branch:
+                        error = _("push creates new remote heads "
+                                  "on branch '%s'!") % branch
+                    else:
+                        error = _("push creates new remote heads!")
+                    if branch in unsynced:
+                        hint = _("you should pull and merge or "
+                                 "use push -f to force")
+                    else:
+                        hint = _("did you forget to merge? "
+                                 "use push -f to force")
                 if branch:
-                    msg = _("push creates new remote heads "
-                            "on branch '%s'!") % branch
-                else:
-                    msg = _("push creates new remote heads!")
-
-                if branch in unsynced:
-                    hint = _("you should pull and merge or use push -f to force")
-                else:
-                    hint = _("did you forget to merge? use push -f to force")
-                raise util.Abort(msg, hint=hint)
+                    repo.ui.debug("new remote heads on branch '%s'\n" % branch)
+                for h in (newhs - oldhs):
+                    repo.ui.debug("new remote head %s\n" % short(h))
+        if error:
+            raise util.Abort(error, hint=hint)
 
         # 6. Check for unsynced changes on involved branches.
         if unsynced:
diff --git a/tests/test-push-warn.t b/tests/test-push-warn.t
--- a/tests/test-push-warn.t
+++ b/tests/test-push-warn.t
@@ -30,6 +30,23 @@
   (you should pull and merge or use push -f to force)
   [255]
 
+  $ hg push --debug ../a
+  pushing to ../a
+  searching for changes
+  examining 1c9246a22a0a:d8d565842d04
+  found incomplete branch 1c9246a22a0a:d8d565842d04
+  searching: 1 queries
+  narrowing 1:1 d8d565842d04
+  found new branch changeset 1c9246a22a0a
+  found new changesets starting at 1c9246a22a0a
+  1 total queries
+  common changesets up to d8d565842d04
+  new remote heads on branch 'default'
+  new remote head 1e108cc5548c
+  abort: push creates new remote heads on branch 'default'!
+  (you should pull and merge or use push -f to force)
+  [255]
+
   $ hg pull ../a
   pulling from ../a
   searching for changes


More information about the Mercurial-devel mailing list