[PATCH 3 of 3 V2] commit: commit should ignore secret heads for "new heads" warning (issue5017)

Laurent Charignon lcharignon at fb.com
Sat Dec 26 22:46:35 CST 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1451191507 28800
#      Sat Dec 26 20:45:07 2015 -0800
# Node ID 50ddc2300ee6860203e80edbd88bf52fb5495c67
# Parent  edd65810df9b8ddb2c78727d2580b8faea6800a7
commit: commit should ignore secret heads for "new heads" warning (issue5017)

The warning exists to keep people from having multi-headed push trouble
but since secret commits are not pushed we don't need to display this
warning.

The logic is implemented at the top level (before displaying the warning
message) to avoid adding phase related code at lower level that is used in
multiple places and doesn't care about phases.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2805,6 +2805,23 @@
         opts = {}
     ctx = repo[node]
     parents = ctx.parents()
+    node = repo.changelog.node
+    if not opts.get('amend') and phases.hassecret(repo):
+        newheads = []
+        for h in bheads:
+            # (issue5017) we should ignore secret heads when prompting for
+            # the 'created new heads' warning message.
+            # Example: when creating 2, we don't want to display the
+            # 'created new heads' warning:
+            # 0(draft)---1(secret)
+            #   \
+            #    --------2(draft)
+            if repo[h].secret():
+                for r in repo.revs("heads(::%s and not secret())", h):
+                    newheads.append(node(r))
+            else:
+                newheads.append(h)
+        bheads = newheads
 
     if (not opts.get('amend') and bheads and node not in bheads and not
         [x for x in parents if x.node() in bheads and x.branch() == branch]
diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -167,7 +167,6 @@
   $ cd ../initialrepo
   $ hg up -q 6 #B'
   $ mkcommit I
-  created new head
   $ hg push ../push-dest
   pushing to ../push-dest
   searching for changes
@@ -618,4 +617,8 @@
   created new head
   $ touch foo2
   $ hg add foo2
+
+(issue5017) commit should ignore secret heads when considering
+"created new head" warning
+
   $ hg commit -s -m "secret commit"


More information about the Mercurial-devel mailing list