Pergunta

I want to add a commit hook that works when a push is received on a gitolite/git server for a given branch and repo combination only (branch 'cat' on repo 'dog').

My environment: git version 1.7.4.1,

What I have done so far:

  1. Touched a file at /home/git/repositories/dog.git/hooks/post-receive.secondary on the git/gitolite server.

  2. Edited the file with the contents:

    #!/bin/sh
    #
    refname="$1"
    oldrev="$2"
    newrev="$3"
    if [ "$refname" == "refs/heads/cat" ]
    then
       touch /tmp/test
    fi
    
  3. Set the owner of the file to the 'git' user

  4. Set the file permissions to 700

  5. Done a commit to "cat" branch of "dog" repo

Results: the test file is not created

Foi útil?

Solução

If I look at Gitolite v2 (g2) hook chaining section, only two hooks are concerned with the ".secondary" extension:

  • The update hook, because it is used in all repos and is critical to gitolite's access control
  • The post-update hook, because it is used in the gitolite-admin repo only, to "compile" the configuration and so on.

  • (post-receive is only involved if mirroring is activated, which shouldn't be the case in your gitolite installation)

So you shouldn't need to declare a post-receive.secondary, just a post-receive hook in your </path/to/gitolite>/hooks/common/, as described in "How to install hooks in gitolite".


The OP specialsauce concludes in the comments:

I needed a post-receive hook in the repository folder (Rather than a secondary one) , which I think was the main reason that it wasn't executing.

The only other thing I changed in the end I believe was setting the perms from 700 (which should have been fine anyway?) to 755.
The hook now executes reliably.

I did not need to run the gl-setup script. Additionally I changed from the var assignment code as outlined above to a "while" on STDIN.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top