changeset 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 ea52a2d4f42c
children 8cb81d75730c
files mercurial/localrepo.py tests/test-push-warn.out tests/test-subrepo.out
diffstat 3 files changed, 28 insertions(+), 19 deletions(-) [+]
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):
--- a/tests/test-push-warn.out	Mon Feb 08 17:28:19 2010 +0100
+++ b/tests/test-push-warn.out	Mon Feb 08 19:44:04 2010 +0100
@@ -2,8 +2,8 @@
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 pushing to ../a
 searching for changes
-abort: push creates new remote heads!
-(did you forget to merge? use push -f to force)
+abort: push creates new remote heads on branch 'default'!
+(you should pull and merge or use push -f to force)
 pulling from ../a
 searching for changes
 adding changesets
@@ -13,7 +13,7 @@
 (run 'hg heads' to see heads, 'hg merge' to merge)
 pushing to ../a
 searching for changes
-abort: push creates new remote heads!
+abort: push creates new remote heads on branch 'default'!
 (did you forget to merge? use push -f to force)
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
@@ -35,7 +35,7 @@
 (branch merge, don't forget to commit)
 pushing to ../c
 searching for changes
-abort: push creates new remote heads!
+abort: push creates new remote heads on branch 'default'!
 (did you forget to merge? use push -f to force)
 1
 pushing to ../c
@@ -44,12 +44,12 @@
 0
 pushing to ../c
 searching for changes
-abort: push creates new remote heads!
-(did you forget to merge? use push -f to force)
+abort: push creates new remote heads on branch 'default'!
+(you should pull and merge or use push -f to force)
 1
 pushing to ../c
 searching for changes
-abort: push creates new remote heads!
+abort: push creates new remote heads on branch 'default'!
 (did you forget to merge? use push -f to force)
 1
 pushing to ../c
@@ -106,8 +106,8 @@
 % fail on multiple head push
 pushing to ../f
 searching for changes
-abort: push creates new remote heads!
-(did you forget to merge? use push -f to force)
+abort: push creates new remote heads on branch 'a'!
+(you should pull and merge or use push -f to force)
 1
 % push replacement head on existing branches
 pushing to ../f
@@ -153,8 +153,8 @@
 created new head
 pushing to h
 searching for changes
-abort: push creates new remote heads!
-(did you forget to merge? use push -f to force)
+abort: push creates new remote heads on branch 'default'!
+(you should pull and merge or use push -f to force)
 
 % check prepush logic with merged branches
 marked working directory as branch a
@@ -167,6 +167,6 @@
 (branch merge, don't forget to commit)
 pushing to j
 searching for changes
-abort: push creates new remote heads!
-(did you forget to merge? use push -f to force)
+abort: push creates new remote heads on branch 'a'!
+(you should pull and merge or use push -f to force)
 
--- a/tests/test-subrepo.out	Mon Feb 08 17:28:19 2010 +0100
+++ b/tests/test-subrepo.out	Mon Feb 08 19:44:04 2010 +0100
@@ -151,7 +151,7 @@
 added 1 changesets with 1 changes to 1 files
 % push -f
 committing subrepository s
-abort: push creates new remote heads!
+abort: push creates new remote heads on branch 'default'!
 pushing ...sub/t
 pushing ...subrepo ss
 searching for changes