Pages

Monday, January 31, 2011

git hooks

git comes by default with a number of hooks. Hooks are little scripts you can place in $GIT_DIR/hooks directory to trigger action at certain points. When git init is run, a handful of example hooks are copied into the hooks directory of the new repository, but by default they are all disabled.
It's good to know that each hook that has execution rights, will indeed get executed. If you have an executable hook by mistake you can end up with this error:

lvarga@lvarga-desktop:~$ git push origin master
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 455 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
*** Project description file hasn't been set
error: hooks/update exited with error code 1
error: hook declined to update refs/heads/master
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'ssh://gitserver/var/www/git/repo.git'

This happened after I changed the permissions of the hooks. I was only using the post-receive hook, all the others were default. I gave all of them execution rights and then I had quite a hard time understanding why some empty hooks were executed.
Then googled a bit and found that the permissions are the problem. It went away after I took out the execution right of all the hooks I didn't use

No comments:

Post a Comment