views:

49

answers:

2

I'm new to Mercurial and want to write some hooks to prevent merging between certain branches and the like. I'm looking for some kind of tutorial that goes through the whole loop.

I've looked at the API and these examples, but I still find it confusing. I've always been better at learning through a tutorial/workshop than by reading a man page or similar.

I can understand how the example code works, but how do I get Mercurial to recognize the functions?

e.g.) I've written this, but I don't understand how to make Mercurial run the code before a commit.

def is_bad_branch_name(ui, repo, **kwargs):
    """
    Checks that a commit is always done on a named branch.
    This function enforces Projectplace's branching convention.
    @return: True if the branch name is invalid.
    @returntype: Boolean
    """
    branch = repo[None].branch()
    branch_names = r'(TT|AZ)(-#)(\d)+(:)[\s\w]*'
    acceptable_branch_names = re.compile(branch_names)
    if not acceptable_branch_names.match(branch):
        ui.warn('invalid branch name %r (use <TT|AZ>-#<number>: <description>)\n')
        return True
    return False
+1  A: 

Let me point out the obvious for the sole reason of me being a desperate rep wh***:

"Chapter 10. Handling repository events with hooks" in BoS's definite hg book.

If you can't figure out a particular hook you want, please ask a more specific question.

Happy hooking!

Geoffrey Zheng
Um, it seems like a fairly valid question MdaG has asked. Why so negative?
wheaties
Sorry I meant my answer is for rw, not the question. Edited.
Geoffrey Zheng
A: 

I've managed to write and make use of hooks now. I found the online documentation lacking, but that might just as well be a problem on my part. What I did was study example code and some trial and error coding as well as ask some questions here. :)

MdaG