contrib/nopushpublish.py
changeset 402 8ef1096ee5ab
parent 401 76df267fd76c
child 413 984be08ef504
equal deleted inserted replaced
401:76df267fd76c 402:8ef1096ee5ab
       
     1 # Extension which prevent changeset to be turn public by push operation
       
     2 
       
     3 from mercurial import extensions, util
       
     4 from mercurial import discovery
       
     5 
       
     6 def checkpublish(orig, repo, remote, outgoing, *args):
       
     7 
       
     8     # is remote publishing?
       
     9     publish = True
       
    10     if 'phases' in remote.listkeys('namespaces'):
       
    11         remotephases = remote.listkeys('phases')
       
    12         publish = remotephases.get('publishing', False)
       
    13 
       
    14     npublish = 0
       
    15     if publish:
       
    16         for rev in outgoing.missing:
       
    17             if repo[rev].phase():
       
    18                 npublish += 1
       
    19     if npublish:
       
    20         repo.ui.warn("Push would publish %s changesets" % npublish)
       
    21 
       
    22     ret = orig(repo, remote, outgoing, *args)
       
    23     if npublish:
       
    24         raise util.Abort("Publishing push forbiden",
       
    25                          hint="Use `hg phase -p <rev>` to manually publish them")
       
    26 
       
    27     return ret
       
    28 
       
    29 def uisetup(ui):
       
    30     extensions.wrapfunction(discovery, 'checkheads', checkpublish)