In my previous article Gitolite administration I covered how to installed and configure the basic elements needed to run Gitolite on your server. At this point I would expect you to be familiar with the basic concepts of Git and gitolite configuration settings. This post demonstrates how to configure hooks Gitolite v2 on your Mac.
Gitolite allows you to configure the settings of the bare git repository it hosts via the gitolite.conf. The most common setting would be to configure the email hooks to send notifications on a push operation. This post shows you how to configure Gitolite to set these parameters through the configuration file.
Normally with git you would place the hook in one of the predefined hooks, we are going to use the post-recieve hook in this sample. Typically this is the most common hook modified for post processing of the push.
Hooks in gitolite
Gitolite mirrors the hooks in each hosted repository. It filters the results through hooks stored in the gitolite settings on the server in the home folder of the git user-created during install. Any hooks you want to have processed get placed inside this folder off the git home. ~/.gitolite/hooks/common. You will have to modify the Gitolite configuration to allow the git repo configuration through the .conf file settings.
.gitolite.rc file changes
On the Git server machine, log on as the Git user, all the modifications will be done on the server for now. In the Git users home folder you have the .gitolite.rc file. This file contains the settings for Gitolite itself, so edit with caution!
- Open the .gitolite.rc file from the command shell. I typically use vi at this point. Locate the following block of code and modify the highlighted values
# VARIABLES WITH A SECURITY IMPACT. READ DOCS BEFORE CHANGING THESE!
# (or http://sitaramc.github.com/gitolite/doc/gitolite.rc.html#_variables_with_a_security_impact)
# $GL_ALL_READ_ALL = 0;
# original value $GL_GITCONFIG_KEYS = "";
$GL_GITCONFIG_KEYS = '*';
- This modification allows ALL git config keys that can be set in a bare repo to be configured by gitolite through the .conf file. Doing this can potentially allow unsafe operations that might compromise the repo security model, so be careful. The GL_GITCONFIG_KEYS recognizes a regex expression so, have fun with that.
- Run Gitolite setup to compile scripts. Remember to add the administrator public key on the command line.
$ gl-setup adminkey.pub
There are other setting that you can make via the .gitolite.rc file. Bu, a warning, proceed with caution. If you don’t understand what is modified, don’t touch it. Also, The new V3 is out, and many settings, in there have been changed. For more information look here: Gitolite V2 advanced RC file settings.
Configure the gitolite hooks
Gitolite chains together the push notification that it receives from the user to the repository that received the push. Gitolite kind of operates like the man in the middle, negotiating the permissions for the user and insuring that any notifications are sent out if Gitolite is configured for that operation. The only hook we are going to examine here is the post-receive hook. This notification is processed when the repository receives a push from another source. This also assumes a non-mirroring push notification, for more information on hooks check out this link: Using hooks.
To add a hook to Gitolite is just as easy as adding it to Git. You need to either provide a Perl script that implements the post processing you want. In this case we want to send an email. You can either write your own, or copy and modify the sample hook installed with Git. I choose the latter. On a Mac you can find the default scripts at /opt/local/share/doc/git-core/contrib/hooks. You can make a symbolic link to the post-receive or copy the file if you want to make modifications. You need to copy the file to ~/.gitolite/hooks/common. make sure the destination file is named post-receive. At this point we are done on the server and we can log out and continue our modifications in the .conf file from your work station.
Now that we are done on the server, log off and continue the modifications through the gitolite.conf file.
@admins = root administrator
@devs = dev1 dev2 dev3
@qa = qa1 qa2
config hooks.mailinglist = firstname.lastname@example.org
config hooks.emailprefix = "[gitolite-admin]"
RW+ = @admins
RW+ = @all
config hooks.mailinglist = email@example.com
config hooks.emailprefix = "[qa]"
RW+ = @qa
R- = dev3
config hooks.mailinglist = "firstname.lastname@example.org, email@example.com"
config hooks.emailprefix = "[project2]"
RW+ = @devs
R = @qa
There you go. Now your projects have email notifications. Email notifications can be set up for email lists and individuals.
In this sample, we have the following email configuration:
- The Gitolite-admin repo only sends out email to those included in the “admins” email list.
- The Testing repo does not send out any email notification.
- The qa repo sends email to all qa personel.
- The project2 repo will send email to all devs and qa.