diff hgext3rd/topic/__init__.py @ 3158:678a9802c56b

topic: add an option to automatically publish topic-less changeset This new option will help playing with merge based workflow.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 01 Nov 2017 16:26:33 +0100
parents f286eefbd20d
children 90515d0bfb08
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Mon Oct 30 19:24:14 2017 +0100
+++ b/hgext3rd/topic/__init__.py	Wed Nov 01 16:26:33 2017 +0100
@@ -72,6 +72,27 @@
 
     [experimental]
     enforce-single-head = yes
+
+Publishing behavior
+===================
+
+Topic vanish when changeset move to the public phases. Moving to the public
+phase usually happens on push, but it is possible ot update that behavior. The
+server needs to have specific config for this.
+
+    # everything pushed become public (the default)
+    [phase]
+    publish = yes
+
+    # nothing push turned public
+    [phase]
+    publish = no
+
+    # topic branches are not published, changeset without topic are
+    [phase]
+    publish = no
+    [experimental]
+    topic.publish-bare-branch = yes
 """
 
 from __future__ import absolute_import
@@ -168,6 +189,9 @@
     configitem('experimental', 'topic-mode',
                default=None,
     )
+    configitem('experimental', 'topic.publish-bare-branch',
+               default=False,
+    )
     configitem('_internal', 'keep-topic',
                default=False,
     )
@@ -381,8 +405,8 @@
             if desc in ('strip', 'repair') or ctr is not None:
                 return tr
 
+            reporef = weakref.ref(self)
             if repo.ui.configbool('experimental', 'enforce-single-head'):
-                reporef = weakref.ref(self)
                 origvalidator = tr.validator
 
                 def validator(tr2):
@@ -391,6 +415,20 @@
                     origvalidator(tr2)
                 tr.validator = validator
 
+            if (repo.ui.configbool('experimental', 'topic.publish-bare-branch')
+                    and (desc.startswith('push')
+                         or desc.startswith('serve'))
+                    ):
+                origclose = tr.close
+                trref = weakref.ref(tr)
+
+                def close():
+                    repo = reporef()
+                    tr2 = trref()
+                    flow.publishbarebranch(repo, tr2)
+                    origclose()
+                tr.close = close
+
             # real transaction start
             ct = self.currenttopic
             if not ct: