Update August 2013, with the latest gitolite:
You now have official specific repo hook:
it's basically just creating a symlink in <repo.git>/hooks
pointing to some file inside $rc{LOCAL_CODE}/hooks/repo-specific
(except the gitolite-admin
repo)
Original answer (
First, if you are using gitolite V3, you can define any hook, including a post-receive
hook (except the update
hook, see using hooks) : previously, with gitolite V2, pre-receive
hook was reserved.
Now you can add a hook by copying it in the gitolite-admin/common/hooks
local clone directory, and pushing gitolite-admin
back to the gitolite server: gitolite will make sure that hook is declared for all bare repos it manages.
You can also add directly your hook on the server at a separate location designed by the $LOCAL_CODE
"rc
" variable ("rc
" means defined in your gitolite.rc
config file): $LOCAL_CODE/hooks/common
. See "customizing gitolite".
The idea is to make sure a gitolite upgrade doesn't erase any of your custom programs.
Simply define a 'post-receive' file, executable (chmod 755
), and copy it in the common/hooks
directory of your choice (gitolite-admin
local repo plus git push
, or .gitolite
on the server, or $LOCAL_CODE
on the server).
Note: that fact that you don't see a 'post-receive.sample
' file doesn't prevent you to define that hook.
If done directly on the server, you need then to run gitolite setup --hooks-only
in order for your custom hooks to be setup on all bare repos.
What you would never do is to copy it directly on one of your bare-repo.git/hooks
directory: that is the job of gitolite to publish "common" hooks to all your bare repo.
That way, you can manage them directly through any clone of gitolite-admin
repo (pushing back that repo will update any hook that you might have changed).
"All bare repo" means your post-receive
hook must know what bare repo it operates on:
You can do that by checking the value of $GIT_DIR
(set to the root .git
directory of the bare repo on which this hook is running).
Finally, for this kind of post-receive
hook, see "Git checkout in post-receive
hook: “Not a git repository '.'
”":
You need to define GIT_DIR
and GIT_WORK_TREE
explicitly to the destination repo in order for your git pull
to succeed.
GIT_WORK_TREE=/Users/me/Sites GIT_DIR=/Users/me/Sites/.git git pull