--- a/mercurial/localrepo.py Sun Feb 07 00:43:22 2010 +0100
+++ b/mercurial/localrepo.py Sun Feb 07 00:43:24 2010 +0100
@@ -1531,13 +1531,7 @@
warn = 1
if warn:
- if not rheads: # new branch requires --force
- self.ui.warn(_("abort: push creates new"
- " remote branch '%s'!\n") %
- self[lheads[0]].branch())
- else:
- self.ui.warn(_("abort: push creates new remote heads!\n"))
-
+ self.ui.warn(_("abort: push creates new remote heads!\n"))
self.ui.status(_("(did you forget to merge?"
" use push -f to force)\n"))
return False
@@ -1568,10 +1562,20 @@
branch = self[n].branch()
localbrheads.setdefault(branch, []).append(n)
+ newbranches = list(set(localbrheads) - set(remotebrheads))
+ if newbranches: # new branch requires --force
+ branchnames = ', '.join("'%s'" % b for b in newbranches)
+ self.ui.warn(_("abort: push creates "
+ "new remote branches: %s!\n")
+ % branchnames)
+ # propose 'push -b .' in the msg too?
+ self.ui.status(_("(use 'hg push -f' to force)\n"))
+ return None, 0
for branch, lheads in localbrheads.iteritems():
- rheads = remotebrheads.get(branch, [])
- if not checkbranch(lheads, rheads, update):
- return None, 0
+ if branch in remotebrheads:
+ rheads = remotebrheads[branch]
+ if not checkbranch(lheads, rheads, update):
+ return None, 0
else:
if not checkbranch(heads, remote_heads, update):
return None, 0
--- a/tests/test-push-warn Sun Feb 07 00:43:22 2010 +0100
+++ b/tests/test-push-warn Sun Feb 07 00:43:24 2010 +0100
@@ -90,38 +90,47 @@
echo 5 > foo
hg -q branch c
hg -q ci -d "1000000 0" -m 5
+hg push ../f; echo $?
hg push -r 4 -r 5 ../f; echo $?
+echo % multiple new branches
+hg -q branch d
+echo 6 > foo
+hg -q ci -d "1000000 0" -m 6
+hg push ../f; echo $?
+hg push -r 4 -r 6 ../f; echo $?
+cd ../g
+
echo % fail on multiple head push
hg -q up 1
-echo 6 > foo
-hg -q ci -d "1000000 0" -m 6
-hg push -r 4 -r 6 ../f; echo $?
+echo 7 > foo
+hg -q ci -d "1000000 0" -m 7
+hg push -r 4 -r 7 ../f; echo $?
echo % push replacement head on existing branches
hg -q up 3
-echo 7 > foo
-hg -q ci -d "1000000 0" -m 7
-hg push -r 6 -r 7 ../f; echo $?
+echo 8 > foo
+hg -q ci -d "1000000 0" -m 8
+hg push -r 7 -r 8 ../f; echo $?
echo % merge of branch a to other branch b followed by unrelated push on branch a
-hg -q up 6
-HGMERGE=true hg -q merge 7
-hg -q ci -d "1000000 0" -m 8
hg -q up 7
-echo 9 > foo
+HGMERGE=true hg -q merge 8
hg -q ci -d "1000000 0" -m 9
-hg push -r 8 ../f; echo $?
+hg -q up 8
+echo 10 > foo
+hg -q ci -d "1000000 0" -m 10
hg push -r 9 ../f; echo $?
+hg push -r 10 ../f; echo $?
echo % cheating the counting algorithm
-hg -q up 8
+hg -q up 9
HGMERGE=true hg -q merge 2
-hg -q ci -d "1000000 0" -m 10
+hg -q ci -d "1000000 0" -m 11
hg -q up 1
-echo 11 > foo
-hg -q ci -d "1000000 0" -m 11
-hg push -r 10 -r 11 ../f; echo $?
+echo 12 > foo
+hg -q ci -d "1000000 0" -m 12
+hg push -r 11 -r 12 ../f; echo $?
echo % checking prepush logic does not allow silently pushing multiple new heads
cd ..
--- a/tests/test-push-warn.out Sun Feb 07 00:43:22 2010 +0100
+++ b/tests/test-push-warn.out Sun Feb 07 00:43:24 2010 +0100
@@ -84,8 +84,24 @@
% push on existing branch and new branch
pushing to ../f
searching for changes
-abort: push creates new remote branch 'c'!
-(did you forget to merge? use push -f to force)
+abort: push creates new remote branches: 'c'!
+(use 'hg push -f' to force)
+1
+pushing to ../f
+searching for changes
+abort: push creates new remote branches: 'c'!
+(use 'hg push -f' to force)
+1
+% multiple new branches
+pushing to ../f
+searching for changes
+abort: push creates new remote branches: 'c', 'd'!
+(use 'hg push -f' to force)
+1
+pushing to ../f
+searching for changes
+abort: push creates new remote branches: 'd'!
+(use 'hg push -f' to force)
1
% fail on multiple head push
pushing to ../f