0

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).

SynozeN Technologies
  • 1,337
  • 1
  • 14
  • 19
  • ok, so when there is a bookmark on the remote server already, I can get it with repo._bookmarks, so this is fine for me to check I am pushing to a bookmark, but the first time a push from local to a remote repo occurs to actually create the bookmark on the remote repo, the bookmark is being not on the remote repo yet, so none exist, and so the check _bookmarks will fail. So I need a way to see if a bookmark is being created for the first time, not just get the _bookmarks already on the remote repo. –  May 30 '17 at 07:15
  • What about checking via `hg incoming` for remote bookmarks not present? – planetmaker May 31 '17 at 11:56

1 Answers1

1

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
navels
  • 80
  • 1
  • 5