I would like to make sure when local repo changes are pushed to our main remote repo, people are pushing changes with a bookmark. So either its the first time they push with a bookmark they have added locally (in their cloned repo), or they are pushing to an already bookmarked line remotely.
I have set up a python hook for mercurial in the hgrc file inside .hgrc like this ...
[hooks] pretxnchangegroup.push = python:./hg/pushhook.py:bookmakrhook
And when I push, I get my callback and my func gets called. How can I get the active bookmark that is coming in with the changes from the user's loca repo to the main repo everyone is cloning from?
I have this signature in my python hook file:
def bookmarkhook(ui, repo, **kwargs)
I can't seem to do anything with repo instance, except get branch etc with
repo[None].branches()
This is a start, as I can at least make sure they are pushing to default, and not creating another head (I only want one branch - default, and many bookmarks).
The bookmark is available in a pretxnclose hook. This works for me (requires a bookmark when pushing to the "release" branch). Handles pushing to an existing bookmark and pushing a new bookmark.
def require_bookmark_on_release(ui, repo, **kwargs):
if repo[None].branch() == 'release' and not repo.currenttransaction().changes['bookmarks']:
ui.warn('A bookmark is required when committing to the release branch\n')
return True
else:
return False