Don't report an error when closing heads during local push (issue387)
authorThomas Arendsen Hein <thomas@intevation.de>
Tue, 05 Dec 2006 23:25:28 +0100
changeset 3803 2aef481ac73c
parent 3802 a0d0d24c4e71
child 3804 302ffecdd726
child 3849 972d14a5a227
Don't report an error when closing heads during local push (issue387)
mercurial/localrepo.py
tests/test-push-warn
tests/test-push-warn.out
--- a/mercurial/localrepo.py	Tue Dec 05 22:46:36 2006 +0100
+++ b/mercurial/localrepo.py	Tue Dec 05 23:25:28 2006 +0100
@@ -1742,8 +1742,13 @@
 
     def addchangegroup(self, source, srctype, url):
         """add changegroup to repo.
-        returns number of heads modified or added + 1."""
 
+        return values:
+        - nothing changed or no source: 0
+        - more heads than before: 1+added heads (2..n)
+        - less heads than before: -1-removed heads (-2..-n)
+        - number of heads stays the same: 1
+        """
         def csmap(x):
             self.ui.debug(_("add changeset %s\n") % short(x))
             return cl.count()
@@ -1836,7 +1841,11 @@
                 self.hook("incoming", node=hex(self.changelog.node(i)),
                           source=srctype, url=url)
 
-        return newheads - oldheads + 1
+        # never return 0 here:
+        if newheads < oldheads:
+            return newheads - oldheads - 1
+        else:
+            return newheads - oldheads + 1
 
 
     def stream_in(self, remote):
--- a/tests/test-push-warn	Tue Dec 05 22:46:36 2006 +0100
+++ b/tests/test-push-warn	Tue Dec 05 23:25:28 2006 +0100
@@ -47,10 +47,11 @@
 HGMERGE=true hg merge 3
 hg ci -m c-d -d "1000000 0"
 
-hg push ../c
-hg push -r 2 ../c
-hg push -r 3 -r 4 ../c
-hg push -f -r 3 -r 4 ../c
-hg push -r 5 ../c
+hg push ../c; echo $?
+hg push -r 2 ../c; echo $?
+hg push -r 3 ../c; echo $?
+hg push -r 3 -r 4 ../c; echo $?
+hg push -f -r 3 -r 4 ../c; echo $?
+hg push -r 5 ../c; echo $?
 
 exit 0
--- a/tests/test-push-warn.out	Tue Dec 05 22:46:36 2006 +0100
+++ b/tests/test-push-warn.out	Tue Dec 05 23:25:28 2006 +0100
@@ -33,22 +33,32 @@
 searching for changes
 abort: push creates new remote branches!
 (did you forget to merge? use push -f to force)
+0
 pushing to ../c
 searching for changes
 no changes found
+0
 pushing to ../c
 searching for changes
 abort: push creates new remote branches!
 (did you forget to merge? use push -f to force)
+0
+pushing to ../c
+searching for changes
+abort: push creates new remote branches!
+(did you forget to merge? use push -f to force)
+0
 pushing to ../c
 searching for changes
 adding changesets
 adding manifests
 adding file changes
 added 2 changesets with 2 changes to 1 files (+2 heads)
+0
 pushing to ../c
 searching for changes
 adding changesets
 adding manifests
 adding file changes
 added 1 changesets with 1 changes to 1 files (-1 heads)
+0