Mercurial > evolve
diff hgext3rd/topic/flow.py @ 5221:af9f40236037 stable
topics: fix auto-publish=abort with servers publishing bare branches
Before this change, servers that automatically publish bare branches were
detected as "non publishing" and the check for automatic publishing on push
assumed nothing was to be published. Now we signal the server-side config to
clients via a new capability so that they can adjust their behavior.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 06 Apr 2020 05:05:07 +0200 |
parents | 48b30ff742cb |
children | 8431bb224862 |
line wrap: on
line diff
--- 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)