1

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 Answer 1

1

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')
5
  • Hi - do have an example as i tried this and I am not seeing my message when I commit. I am not using a server all I am doing is committing to a repository on my local kubuntu laptop May 31, 2014 at 10:36
  • I confess I'm just going by the docs; I don't use bzr. According to this, the plugins should be placed in ~/.bazaar/plugins. The plugin directory can also be specified by defining BZR_PLUGIN_PATH.
    – unutbu
    May 31, 2014 at 11:28
  • Thanks I'll check it out an let you know. Thanks so much for the help May 31, 2014 at 12:28
  • unindent does not match any outer indentation level - do you know what this error means? May 31, 2014 at 13:04
  • Thanks I see that python relies on specific indentation. I got it to work. Thanks for your help Jun 1, 2014 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.