I would like bazaar to write revision number on commit to a file in the committed branch so that this modification is included in the commit.
I looked at hooks but the pre_commit hook is only run after the changeset is created, thus the modification performed by it is not committed.
I found a related question: Bazaar: Modify file content before commit via hook? , however, the proposed bzr-keywords solution does not work either as its write conversion is not applied on commit:
``bzr commit`` does not implicitly apply write converters after comitting files. If this makes sense for a given plugin providing a content filter, the plugin can usually achieve this effect by using a ``start_commit`` or ``post_commit`` hook.
which gets me back to the pre_commit hook problem.
My reason for doing this: my software reads its version from a version file on compilation. The version is composed of main number, branch number and revision number (eg 5.3.78). I want bazaar to write the actual version to the version file automatically on commit.
You should use start_commit
hook because this is the only way to change file before commit: http://doc.bazaar.canonical.com/bzr.2.3/en/user-reference/hooks-help.html#start-commit
start_commit
Called before a commit is performed on a tree. The start commit hook is able to change the tree before the commit takes place. start_commit is called with the bzrlib.mutabletree.MutableTree that the commit is being performed on.