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
Hello-World
  • 9,277
  • 23
  • 88
  • 154

1 Answers1

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')
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • 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 – Hello-World May 31 '14 at 10:36
  • I confess I'm just going by the docs; I don't use bzr. [According to this](http://ifdeflinux.blogspot.com/2012/07/a-bazaar-pre-commit-hook-to-look-for.html), the plugins should be placed in `~/.bazaar/plugins`. The plugin directory can also be specified by defining [BZR_PLUGIN_PATH](http://doc.bazaar.canonical.com/beta/en/user-reference/configuration-help.html#bzr-plugin-path). – unutbu May 31 '14 at 11:28
  • Thanks I'll check it out an let you know. Thanks so much for the help – Hello-World May 31 '14 at 12:28
  • unindent does not match any outer indentation level - do you know what this error means? – Hello-World May 31 '14 at 13:04
  • Thanks I see that python relies on specific indentation. I got it to work. Thanks for your help – Hello-World Jun 01 '14 at 14:20