tags:

views:

194

answers:

3

In subversion, hooks are written on a per-repository basis. Each hook is written in a descriptive filename (e.g. pre-commit) in a folder named "hooks" at the root of the repository. According to the BZR docs, hooks are typically installed globally (e.g. in the ~/.bazaar/plugins/ directory).

Is it possible to create, say, a pre-commit hook that is committed to the branch and that runs without a user having to install a plugin?

I see in the docs and in some code discussions a reference to something called "branch hooks," which sounds promising.

I found this blog: http://schettino72.wordpress.com/2008/01/20/how-to-execute-tests-on-a-bazaar-pre-commit-hook/, which quotes:

"plugins in bazaar are not project specific. so you cant control in which projects (branches) your plugin will be applied (it will be applied to all)."

which is less promising. The blog gives a workaround in that you write and install a plugin that calls hooks in your repository if they exist. Ideally, I want not to rely on users to install plugins for a really basic hook to run, namely a simple test. Is this possible?

A: 

No, your users have to install the plugin to activate your hook.

bialix
A: 

You can use bazaar server and install hooks on them.

also You may find interested next links:

http://people.samba.org/bzr/jelmer/bzr-shell-hooks/trunk/

http://bazaar.launchpad.net/~stianse/%2Bjunk/bzr-shell-hooks/

vitaly.v.ch
+1  A: 

I did some research into this and found motivation behind the lack of branch-specific hooks in distributed revision control systems. I had compared to Subversion, a centralized RCS, as an example of the desired feature.

GIT and Mercurial are distributed RCSs (like Bazaar) that have tools for hooks, including different approaches to branch-specific hooks and global hooks. Regardless, the hooks are not revision controlled and they require the user of the branch to enable them due to the security risk. In the Mercurial documentation on hooks, under the section titled "Hooks and security," it says:

In Mercurial, hooks are not revision controlled, and do not propagate when you clone, or pull from, a repository. The reason for this is simple: a hook is a completely arbitrary piece of executable code. It runs under your user identity, with your privilege level, on your machine.

It would be extremely reckless for any distributed revision control system to implement revision-controlled hooks, as this would offer an easily exploitable way to subvert the accounts of users of the revision control system.

In a centralized RCS, like Subversion, the hooks are run on the repository server, so user permissions and server-setup restrict the impact of a damaging hook script. In a distributed RCS, the hooks are typically run on the user's local machine, which is risky.

As vitaly.v.ch mentions, a Bazaar server could be setup to run hooks when pushed to and pulled from. But then a pre-commit hook doesn't make sense, since the commits happen on the user's machine. It would then be more like a pre-push hook.

Bazaar has all the needed functionality for hooks, but individual user configuration is required to install and enable them due to the security risk they pose.

Arthur Hebert