hgext3rd/topic/flow.py
branchstable
changeset 5266 af9f40236037
parent 4814 48b30ff742cb
child 5276 8431bb224862
--- a/hgext3rd/topic/flow.py	Sat Mar 21 15:04:18 2020 +0100
+++ b/hgext3rd/topic/flow.py	Mon Apr 06 05:05:07 2020 +0200
@@ -108,3 +108,57 @@
                             extendpushoperation)
     extensions.wrapfunction(exchange, '_pushdiscoveryphase', wrapphasediscovery)
     exchange.pushdiscoverymapping[b'phase'] = exchange._pushdiscoveryphase
+
+def replacecheckpublish(orig, pushop):
+    listkeys = exchange.listkeys
+    repo = pushop.repo
+    ui = repo.ui
+    behavior = ui.config(b'experimental', b'auto-publish')
+    if pushop.publish or behavior not in (b'warn', b'confirm', b'abort'):
+        return
+
+    # possible modes are:
+    #
+    # none -> nothing is published on push
+    # all  -> everything is published on push
+    # auto -> only changeset without topic are published on push
+    #
+    # Unknown mode is assumed "all" for safety.
+    #
+    # TODO: do a wider brain storming about mode names.
+
+    mode = b'all'
+    remotephases = listkeys(pushop.remote, b'phases')
+    if not remotephases.get(b'publishing', False):
+        mode = b'none'
+        for c in pushop.remote.capabilities():
+            if c.startswith(b'ext-topics-publish'):
+                mode = c.split(b'=', 1)[1]
+                break
+    if mode == b'none':
+        return
+
+    if pushop.revs is None:
+        published = repo.filtered(b'served').revs(b'not public()')
+    else:
+        published = repo.revs(b'::%ln - public()', pushop.revs)
+    if mode == b'auto':
+        published = repo.revs(b'%ld::(%ld - topic())', published, published)
+    if published:
+        if behavior == b'warn':
+            ui.warn(
+                _(b'%i changesets about to be published\n') % len(published)
+            )
+        elif behavior == b'confirm':
+            if ui.promptchoice(
+                _(b'push and publish %i changesets (yn)?$$ &Yes $$ &No')
+                % len(published)
+            ):
+                raise error.Abort(_(b'user quit'))
+        elif behavior == b'abort':
+            msg = _(b'push would publish %i changesets') % len(published)
+            hint = _(
+                b"use --publish or adjust 'experimental.auto-publish'"
+                b" config"
+            )
+            raise error.Abort(msg, hint=hint)