# HG changeset patch # User Benoit Boissinot # Date 2010-02-06 23:43:24 # Node ID 844d83da2da9fb9890efe1d8701f3554db1a7cb9 # Parent 36b6b5ef78208c496d2cbca31a49fb90ac8bd607 prepush: warn about every new outgoing named branch, not just the first diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1531,13 +1531,7 @@ class localrepository(repo.repository): 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 @@ class localrepository(repo.repository): 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 diff --git a/tests/test-push-warn b/tests/test-push-warn --- a/tests/test-push-warn +++ b/tests/test-push-warn @@ -90,38 +90,47 @@ hg -q up 0 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 .. diff --git a/tests/test-push-warn.out b/tests/test-push-warn.out --- a/tests/test-push-warn.out +++ b/tests/test-push-warn.out @@ -84,8 +84,24 @@ 0 % 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