diff mercurial/localrepo.py @ 10396:65a90c8e11ee

prepush: add more precise error messages Part of the patch is from timeless@mozdev.org - indicate the branch name where there are multiple heads - give better advice when hitting a possible race, where new heads are added between discovery and the call to branchmap(). In that case, asking the user to merge isn't helpful, since only remote has the changes.
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Mon, 08 Feb 2010 19:44:04 +0100
parents 9be6c5900c07
children 2d30d66a89ad
line wrap: on
line diff
--- a/mercurial/localrepo.py	Mon Feb 08 17:28:19 2010 +0100
+++ b/mercurial/localrepo.py	Mon Feb 08 19:44:04 2010 +0100
@@ -1491,7 +1491,7 @@
         update, updated_heads = self.findoutgoing(remote, common, remote_heads)
         msng_cl, bases, heads = self.changelog.nodesbetween(update, revs)
 
-        def checkbranch(lheads, rheads, updatelb):
+        def checkbranch(lheads, rheads, updatelb, branchname=None):
             '''
             check whether there are more local heads than remote heads on
             a specific branch.
@@ -1527,9 +1527,18 @@
                     warn = 1
 
             if warn:
-                self.ui.warn(_("abort: push creates new remote heads!\n"))
-                self.ui.status(_("(did you forget to merge?"
-                                 " use push -f to force)\n"))
+                if branchname is not None:
+                    msg = _("abort: push creates new remote heads"
+                            " on branch '%s'!\n") % branchname
+                else:
+                    msg = _("abort: push creates new remote heads!\n")
+                self.ui.warn(msg)
+                if len(lheads) > len(rheads):
+                    self.ui.status(_("(did you forget to merge?"
+                                     " use push -f to force)\n"))
+                else:
+                    self.ui.status(_("(you should pull and merge or"
+                                     " use push -f to force)\n"))
                 return False
             return True
 
@@ -1570,7 +1579,7 @@
                     for branch, lheads in localbrheads.iteritems():
                         if branch in remotebrheads:
                             rheads = remotebrheads[branch]
-                            if not checkbranch(lheads, rheads, update):
+                            if not checkbranch(lheads, rheads, update, branch):
                                 return None, 0
                 else:
                     if not checkbranch(heads, remote_heads, update):