git hook scripts

Jannis Pohlmann jannis at xfce.org
Sat May 9 17:06:11 CEST 2009


Hey,

I'm currently fiddling with the hook scripts. I'd like to have a
directory where all our scripts are stored. To make the setup modular,
I'm currently using the following setup:

Repository configuration
========================

Here I'm using a section called "xfcehooks". Every repository should
have it in its git config file, like this;

  [xfcehooks]
    mailinglist = xfce4-commits at xfce.org
    envelopesender = true
    gcobjects = 100
    repoadmin = xfce4-dev at xfce.org

Hook scripts
============

I have a directory called $XFCE_GIT_HOOK_DIR with the following
layout:

  ./hooks/update-01-block-invalid-updates
  ./hooks/update-02-check-permissions
  ./hooks/update-03-send-commit-mails
  ./hooks/post-receive-01-update-docs
  ./lib/init
  ./update
  ./post-receive
  
The ./hooks directory contains several hook scripts, each belonging to
one git hook (e.g. update or post-receive) and each serving exactly one
purpose (e.g. update-03-send-commit-mails *only* sends commit mails).
The numbers (01, 02, etc.) can be used to prioritize the scripts. For
the update hooks this means that if update-02-check-permissions fails,
the entire update fails and update-03-send-commit-mails is not executed.

The ./lib directory contains commonly required functions, all of them
made available by importing the ./lib/init script.

The toplevel scripts (here: ./update and ./post-receive) are what we
link to from the hooks directory of each repository. They import
./lib/init and execute the ./hook scripts in prioritized order.
This is how the update script currently looks like:

  # Initialize the hook script
  . $XFCE_GIT_HOOK_DIR/lib/init

  for script in $XFCE_GIT_HOOK_DIR/hooks/update-*; do
    if ! xfce_git_hook_is_excluded `basename $script`; then
      $script $* || exit 1
    fi
  done

xfce_git_hook_is_excluded() uses two environment variables to find out
whether a hook script should be executed or not: $XFCE_GIT_HOOK_INCLUDE
and $XFCE_GIT_HOOK_EXCLUDE.

How to use the scripts
======================

There are two possiblities:

  1) Directly link to the toplevel hooks, e.g. in a repository:
     
       ln -s $XFCE_GIT_HOOK_DIR/update hooks/update

     This will not set $XFCE_GIT_HOOK_INCLUDE/$XFCE_GIT_HOOK_EXCLUDE
     and will thus execute *all* hooks.

  2) Create a script that sets $XFCE_GIT_HOOK_INCLUDE/EXCLUDE and calls
     the toplevel hook. E.g. for all private repositories, do
     something like this:

       XFCE_GIT_HOOK_EXCLUDE="update-03-send-commit-mails"
       . $XFCE_GIT_HOOK_DIR/update

I'm currently thinking about how to exclude certain scripts by default,
like the update docs script. I've created a repository

  http://git.xfce.org/jannis/xfce-git-hooks

in which I'll work on the hooks. We can import them into Brian's git
migration repository at a later stage, I guess.

  - Jannis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://mail.xfce.org/pipermail/xfce4-dev/attachments/20090509/39318c09/attachment.pgp>


More information about the Xfce4-dev mailing list