diff mercurial/discovery.py @ 19840:b00ba31313c3

discovery: abort also when pushing multiple headed new branch Before this patch, pushing with --new-branch permits to create multiple headed branch on the destination repository. But permitting to create new branch should be different from permitting to create multiple heads on branch. This patch prevents from careless pushing multiple headed new branch, and requires --force to push such branch forcibly.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 01 Oct 2013 00:26:22 +0900
parents f3b21beb9802
children bfc6ed892349
line wrap: on
line diff
--- a/mercurial/discovery.py	Mon Sep 30 17:42:38 2013 +0200
+++ b/mercurial/discovery.py	Tue Oct 01 00:26:22 2013 +0900
@@ -269,13 +269,12 @@
     allfuturecommon = set(c.node() for c in repo.set('%ld', outgoing.common))
     allfuturecommon.update(allmissing)
     for branch, heads in sorted(headssum.iteritems()):
-        if heads[0] is None:
-            # Maybe we should abort if we push more that one head
-            # for new branches ?
-            continue
         candidate_newhs = set(heads[1])
         # add unsynced data
-        oldhs = set(heads[0])
+        if heads[0] is None:
+            oldhs = set()
+        else:
+            oldhs = set(heads[0])
         oldhs.update(heads[2])
         candidate_newhs.update(heads[2])
         dhs = None
@@ -310,7 +309,16 @@
             newhs = candidate_newhs
         if [h for h in heads[2] if h not in discardedheads]:
             unsynced = True
-        if len(newhs) > len(oldhs):
+        if heads[0] is None:
+            if 1 < len(newhs):
+                dhs = list(newhs)
+                if error is None:
+                    error = (_("push creates multiple headed new branch '%s'")
+                             % (branch))
+                    hint = _("merge or"
+                             " see \"hg help push\" for detail about"
+                             " pushing new heads")
+        elif len(newhs) > len(oldhs):
             # strip updates to existing remote heads from the new heads list
             dhs = sorted(newhs - bookmarkedheads - oldhs)
         if dhs: