bzr How to create a commit hook?

113 views Asked by At

I am trying to make my first commit hook and it is not working. I got the idea from here http://doc.bazaar.canonical.com/beta/en/user-guide/hooks.html

What I am trying todo is to start by making my own custom commit message. but this does not work. please can you help?

I made a python file called commit_hook.py

from bzrlib import branch


def my_commit_hook(push_result):
    print "I made this and the new revno is %d" % commit_result.new_revno


branch.Branch.hooks.install_named_hook('post_commit', post_commit_hook,
                                 'My post_commit hook')

I put the file commit_hook.py in my .bzr hidden folder in my repository. I made the plugins directory? is that correct?

.bzr/
├── 
├── branch-format
├── branch-lock
├── plugins
│   └── commit_hook.py
├── README
1

There are 1 answers

5
unutbu On BEST ANSWER

Per the docs:

post_commit is called with (local, master, old_revno, old_revid, new_revno, new_revid).

Therefore,

def my_commit_hook(local, master, old_revno, old_revid, 
                   new_revno, new_revid):

Also, post_commit_hook should be my_commit_hook:

branch.Branch.hooks.install_named_hook('post_commit', 
                                       my_commit_hook,
                                       'My post_commit hook')