gitgitolite

gitolite post receive hook for specific bare repo


After I push my local git repo to the server:

$ git push origin master

I want the bare repo on the server (after it received the push from me) to:

$ cd /Users/me/Sites
$ git pull
$ exit

I've looked at some questions here and they mention hooks in $HOME/gitolite/hooks,

but here's what I'm working with:

git@mm:gitolite $ pwd
/Users/git/gitolite
git@mm:gitolite $ ls
.git/                 README.txt            install*
CHANGELOG             check-g2-compat*      src/
COPYING               convert-gitosis-conf* t/

How do I add a post-receive hook for a specific bare repo?

If I go into my bare repo:

git@mm:bare-repo.git $ ls hooks
applypatch-msg.sample*     pre-rebase.sample*
commit-msg.sample*         prepare-commit-msg.sample*
post-update.sample*        update@
pre-applypatch.sample*     update.sample*
pre-commit.sample*

I don't see a post-receive hook. What gives?


Solution

  • 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