changeset 12998:91cb08a9e7fb

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.
author Adrian Buehlmann <adrian@cadifra.com>
date Thu, 11 Nov 2010 15:51:20 +0100
parents a50606327538
children cc4e13c92dfa
files mercurial/discovery.py tests/test-push-warn.t
diffstat 2 files changed, 39 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/discovery.py	Thu Nov 11 15:42:27 2010 +0100
+++ b/mercurial/discovery.py	Thu Nov 11 15:51:20 2010 +0100
@@ -278,20 +278,30 @@
 
         # 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:
--- a/tests/test-push-warn.t	Thu Nov 11 15:42:27 2010 +0100
+++ b/tests/test-push-warn.t	Thu Nov 11 15:51:20 2010 +0100
@@ -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