push: fix bug in prepush logic and its tests stable
authorSune Foldager <cryo@cyanite.org>
Fri, 26 Mar 2010 17:02:36 +0100
branchstable
changeset 10771 01f097c4ae66
parent 10770 fe39f0160c74
child 10772 1e819576e926
push: fix bug in prepush logic and its tests
mercurial/localrepo.py
tests/test-push-warn
tests/test-push-warn.out
--- a/mercurial/localrepo.py	Fri Mar 26 17:02:23 2010 +0100
+++ b/mercurial/localrepo.py	Fri Mar 26 17:02:36 2010 +0100
@@ -1575,9 +1575,8 @@
                         localbrheads = self.branchmap()
                     else:
                         localbrheads = {}
-                        for n in heads:
-                            branch = self[n].branch()
-                            localbrheads.setdefault(branch, []).append(n)
+                        ctxgen = (self[n] for n in msng_cl)
+                        self._updatebranchcache(localbrheads, ctxgen)
 
                     newbranches = list(set(localbrheads) - set(remotebrheads))
                     if newbranches: # new branch requires --force
--- a/tests/test-push-warn	Fri Mar 26 17:02:23 2010 +0100
+++ b/tests/test-push-warn	Fri Mar 26 17:02:36 2010 +0100
@@ -166,4 +166,32 @@
 hg -R k push -r a j
 echo
 
+echo % prepush -r should not allow you to sneak in new heads
+hg init l
+cd l
+echo a >> foo
+hg -q add foo
+hg -q branch a
+hg -q ci -d '0 0' -ma
+hg -q up null
+echo a >> foo
+hg -q add foo
+hg -q branch b
+hg -q ci -d '0 0' -mb
+cd ..
+hg -q clone l m -u a
+cd m
+hg -q merge b
+hg -q ci -d '0 0' -mmb
+hg -q up 0
+echo a >> foo
+hg -q ci -ma2
+hg -q up 2
+echo a >> foo
+hg -q branch -f b
+hg -q ci -d '0 0' -mb2
+hg -q merge 3
+hg -q ci -d '0 0' -mma
+hg push ../l -b b
+
 exit 0
--- a/tests/test-push-warn.out	Fri Mar 26 17:02:23 2010 +0100
+++ b/tests/test-push-warn.out	Fri Mar 26 17:02:36 2010 +0100
@@ -100,7 +100,7 @@
 1
 pushing to ../f
 searching for changes
-abort: push creates new remote branches: d!
+abort: push creates new remote branches: c, d!
 (use 'hg push -f' to force)
 1
 % fail on multiple head push
@@ -167,6 +167,11 @@
 (branch merge, don't forget to commit)
 pushing to j
 searching for changes
+abort: push creates new remote branches: b!
+(use 'hg push -f' to force)
+
+% prepush -r should not allow you to sneak in new heads
+pushing to ../l
+searching for changes
 abort: push creates new remote heads on branch 'a'!
-(you should pull and merge or use push -f to force)
-
+(did you forget to merge? use push -f to force)