Patchwork [2,of,2] discovery: abort also when pushing multiple headed new branch

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 29, 2013, 12:31 p.m.
Message ID <8f21d790d3b03569f700.1377779466@feefifofum>
Download mbox | patch
Permalink /patch/2287/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - Aug. 29, 2013, 12:31 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1377777067 -32400
#      Thu Aug 29 20:51:07 2013 +0900
# Node ID 8f21d790d3b03569f70043e4690b056e0de84795
# Parent  7cee001f451b6a097ed754db1a988d1035362eaf
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.
Matt Mackall - Sept. 18, 2013, 11:34 p.m.
On Thu, 2013-09-05 at 20:13 -0500, Kevin Bullock wrote:
> On 29 Aug 2013, at 7:31 AM, FUJIWARA Katsunori wrote:
> 
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> > # Date 1377777067 -32400
> > #      Thu Aug 29 20:51:07 2013 +0900
> > # Node ID 8f21d790d3b03569f70043e4690b056e0de84795
> > # Parent  7cee001f451b6a097ed754db1a988d1035362eaf
> > 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.
> 
> I think I agree that this is a desirable fix, but I'd like to hear other opinions.

Sounds right to me.

Patch

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -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,15 @@ 
             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 = _("did you forget to merge? "
+                             "see \"hg help push\" for detail about pushing")
+        elif len(newhs) > len(oldhs):
             # strip updates to existing remote heads from the new heads list
             dhs = sorted(newhs - bookmarkedheads - oldhs)
         if dhs:
diff --git a/tests/test-push-warn.t b/tests/test-push-warn.t
--- a/tests/test-push-warn.t
+++ b/tests/test-push-warn.t
@@ -354,6 +354,29 @@ 
   adding file changes
   added 1 changesets with 1 changes to 1 files
 
+Pushing muliple headed new branch:
+
+  $ echo 14 > foo
+  $ hg -q branch f
+  $ hg -q ci -m 14
+  $ echo 15 > foo
+  $ hg -q ci -m 15
+  $ hg -q up 14
+  $ echo 16 > foo
+  $ hg -q ci -m 16
+  $ hg push --branch f --new-branch ../f
+  pushing to ../f
+  searching for changes
+  abort: push creates multiple headed new branch 'f'
+  (did you forget to merge? see "hg help push" for detail about pushing)
+  [255]
+  $ hg push --branch f --new-branch --force ../f
+  pushing to ../f
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 3 changesets with 3 changes to 1 files (+1 heads)
 
 Checking prepush logic does not allow silently pushing
 multiple new heads: