hgext3rd/topic/flow.py
changeset 3235 8a772f0c54d9
parent 3226 5dfe4e5cf9e4
child 3282 3675fe74521d
--- a/hgext3rd/topic/flow.py	Sat Dec 09 05:05:39 2017 +0100
+++ b/hgext3rd/topic/flow.py	Sat Dec 09 06:13:28 2017 +0100
@@ -30,6 +30,31 @@
         nodes = [cl.node(r) for r in topublish]
         repo._phasecache.advanceboundary(repo, tr, phases.public, nodes)
 
+def rejectuntopicedchangeset(repo, tr):
+    """Reject the push if there are changeset without topic"""
+    if not tr.changes['revs']: # no new revs
+        return
+
+    mode = repo.ui.config('experimental', 'topic-mode.server', 'ignore')
+
+    revs = list(tr.changes['revs'])
+    untopiced = repo.revs('not public() and (%ld:) - hidden() - topic()', revs)
+    if untopiced:
+        num = len(untopiced)
+        fnode = repo[untopiced.first()].hex()[:10]
+        if num == 1:
+            msg = _("%s") % fnode
+        else:
+            msg = _("%s and %d more") % (fnode, num - 1)
+        if mode == 'warning':
+            fullmsg = _("pushed draft changeset without topic: %s\n")
+            repo.ui.warn(fullmsg % msg)
+        elif mode == 'enforce':
+            fullmsg = _("rejecting draft changesets: %s")
+            raise error.Abort(fullmsg % msg)
+        else:
+            repo.ui.warn(_("unknown 'topic-mode.server': %s\n" % mode))
+
 def wrappush(orig, repo, remote, *args, **kwargs):
     """interpret the --publish flag and pass it to the push operation"""
     newargs = kwargs.copy()