2

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

  • If you add an echo in your script, is it displayed? And do you have gitolite v2 or v3? – VonC Jun 15 '12 at 16:03
  • @VonC - from the src/CHANGELOG I believe I am running v2.0 but I can't find a binary to execute to verify this. I will check the echo command in the script and respond shortly – specialsauce Jun 15 '12 at 16:20
  • Simple: if you have '`gl-xxx`' commands in your gitolite, this is V2. – VonC Jun 15 '12 at 16:43
  • @VonC - they are not in my PATH but there are gl-xxx commands in /home/git/.gitolite/src, yes – specialsauce Jun 15 '12 at 16:45
  • and if I run the script manually, passing in the refname then yes it executes fine, it is simply not getting executed, or failing somehow when I commit code to that branch on that repo – specialsauce Jun 15 '12 at 17:18

1 Answers1

1

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • there is a `post-receive.mirrorpush` symlink, which is why I used the `.secondary` filename. With regard to putting the hook in `/hooks/common/`, I explicitly wanted this hook only to take effect for commits to a single repository, whereas I beleive hooks in the common location would trigger on a commit to any repository – specialsauce Jun 15 '12 at 19:21
  • @user1459145 no, you should use a .secondary because of a `post-receive.mirrorpush`: the doc is clear: "Shipped as `post-receive.mirrorpush`, it is renamed to '`post-receive`' and installed as part of the mirroring setup": if you don't see a '`post-receive`', you can create your own. – VonC Jun 15 '12 at 19:25
  • thank you for the clarification. However, I have moved the file to `post-receive` and run a second commit, and still see no temp file created. – specialsauce Jun 15 '12 at 19:30
  • @user1459145 did you put an echo in that script, just to see if it was at least called? Did you first symlink your script to all repo by running `gl-setup` again? – VonC Jun 15 '12 at 19:33
  • thanks for your perseverance. the echo is in that script, yes. So the script's correct home is `/hooks/common/post-receive`, and it will only actually execute for a given repository if that repo has the symlink from `/hooks/post-receive` to `/hooks/common/post-receive` ? – specialsauce Jun 15 '12 at 19:47
  • @user1459145 yes, the symlink needs to be in place, which `gl-setup` should do automatically for you. – VonC Jun 15 '12 at 19:49
  • I manually relocated the file and set up the symlink as above, and this still did not work. I am loathe to reconfigure using gl-setup after reading the documentation for it since it doesn't look ever to have been run on this host and I do not want to break any existing configuration. – specialsauce Jun 15 '12 at 19:59
  • @user1459145 interesting: a gitolite without gl-setup. I am not sure how it can work. I would recommend setting up in a different path a gitolite V3 (a simple clone will be enough, followed by a `gitolite setup`, like I did in https://github.com/VonC/compileEverything/blob/master/gitolite/install_or_update_gitolite.sh) – VonC Jun 15 '12 at 20:17
  • thank you for your assistance and persistence, this problem is now resolved. – specialsauce Jun 18 '12 at 09:09
  • @specialsauce: excellent. Do you have any details on the specifics of the resolution? I will edit my answer and add them, for other readers to benefit from. – VonC Jun 18 '12 at 10:09
  • your basic answer was correct, that 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 beleive 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. I'm not 100% sure which of these changes resolved the issue. – specialsauce Jun 18 '12 at 13:26
  • @specialsauce: understood. I have edited the answer to include your conclusions, for more visibility. – VonC Jun 18 '12 at 13:34