Bazaar: Automatic remote revision writing to remote branch on push

310 Views Asked by At

I would like the latest remote revision number to be committed to a file of the remote tree on each push. The following thread answers the question of doing it locally on commit, is there a way to do it remotely on push?

In other words, is there a "start_push"-like analogy/workaround to start_commit?

I'd like to do this in order to allow diverging local trees with their own versioning while keeping separate versioning for the 'central' tree. So, different developers should be able to branch from the central server, then diverge in their local trees by any local commits and push/merge back. All the trees should be versioned automatically and uniquely by a combination of a tree sequence and its revision which is written to a file which is part of the tree. For example, (a developer's xyz local) commit with revision number 127 of tree 'xyz' commits 'xyz.127' into a VERSION file of the tree. However, pushing this revision to the 'central' tree should commit for instance 'central.98' to the central tree (if the last revision in the 'central' tree was 97).

It have it working fine for the local commits but I do not know how to achieve the desired behaviour on the remote push. Note that it is not a problem that the local fork of the revision will be different from the remote one; it is actually desired.

Alternatively, a different setup achieving the same aim (diverging local trees with their own versioning and separate versioning for the 'central' tree) would be very much welcome too!

1

There are 1 best solutions below

6
On

You would need to install a plugin on the server that registers for the post-change-branch-tip hook.

Untested example:

from bzrlib.urlutils import local_path_from_url
from bzrlib.osutils import pathjoin

def post_change_branch_tip_hook(params):
    root = local_path_from_url(params.branch.base)
    path = pathjoin(self.root, 'revno.txt')
    f = open(path, 'w')
    try:
        f.write('%s\n' % params.new_revno)
    finally:
        f.close()