hgext3rd/topic/flow.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 01 Nov 2017 16:26:33 +0100
changeset 3158 678a9802c56b
parent 3157 f286eefbd20d
child 3159 90515d0bfb08
permissions -rw-r--r--
topic: add an option to automatically publish topic-less changeset This new option will help playing with merge based workflow.

from __future__ import absolute_import

from mercurial import (
    error,
    node,
    phases,
)

from mercurial.i18n import _

def enforcesinglehead(repo, tr):
    for name, heads in repo.filtered('visible').branchmap().iteritems():
        if len(heads) > 1:
            hexs = [node.short(n) for n in heads]
            raise error.Abort(_('%d heads on "%s"') % (len(heads), name),
                              hint=(', '.join(hexs)))

def publishbarebranch(repo, tr):
    """Publish changeset without topic"""
    if 'node' not in tr.hookargs: # no new node
        return
    startnode = node.bin(tr.hookargs['node'])
    topublish = repo.revs('not public() and (%n:) - hidden() - topic()', startnode)
    if topublish:
        cl = repo.changelog
        nodes = [cl.node(r) for r in topublish]
        repo._phasecache.advanceboundary(repo, tr, phases.public, nodes)