Search code examples
macosapachegitgit-post-receive

Git post-receive over HTTP in OS X


My setup is:
1. OS X runnig apache server for Git storage.
2. My directory for Git projects is here: /Library/WebServer/Documents/CI
3. I've followed this tutorial: http://www.pkgbox.org/wordpress/2011/08/setting-up-a-git-server-on-macos-x-lion/ and setted up Git access over HTTP
4. My gitrepo.conf is like:

DavLockDB "/var/www/DavLock/Lock"
DavMinTimeout 28800

<Directory /Library/WebServer/Documents/CI>
  DAV On
  Deny from all
  AuthType Basic
  AuthName "Area51 git repositories"
  AuthUserFile /etc/apache2/other/htpasswd-git
  AuthGroupFile /etc/apache2/other/htgroup-git

</Directory>
<Directory /Library/WebServer/Documents/CI/ci_test.git>
Allow from all 
Order allow,deny
Require valid-user
<Limit GET>
Require group myproject-reader
</Limit>
<Limit GET PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require group myproject-writer
</Limit>
</Directory>

5. Authentication over HTTP is working, I've got different users and different groups and it is all working fine.

My problem is: I want to be able to use post-receive hook in my git. I've read this question: Git post-receive hook not working And what I'm getting from there is that I need to setup SMART HTTP. Unfortunatly this link: http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html get's me 404.

I've read here: http://progit.org/2010/03/04/smart-http.html but I'm really newbie in setting up servers and I don't understand what I am suppose to do... Could you provide me with valid configuration for activating GIT hooks?

Proposed solution Changing to SMART HTTP.

Here is my current gitrepo.conf

<VirtualHost *:80>
  ServerName ciserver.smt
  DocumentRoot /Library/WebServer/Documents/CI

  SetEnv GIT_PROJECT_ROOT /Library/WebServer/Documents/CI
  SetEnv GIT_HTTP_EXPORT_ALL

  ScriptAlias / /usr/libexec/git-core/git-http-backend/
  AliasMatch ^/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$          /Library/WebServer/Documents/CI/$1
  AliasMatch ^/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /Library/WebServer/Documents/CI/$1

  ScriptAliasMatch \
    "(?x)^/(.*/(HEAD | \
    info/refs | \
    objects/(info/[^/]+ | \
        [0-9a-f]{2}/[0-9a-f]{38} | \
        pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
    git-(upload|receive)-pack))$" \
    /usr/libexec/git-core/git-http-backend/$1

  <LocationMatch "^/.*/git-receive-pack$">
    AuthType Basic
    AuthName "Git"
    AuthUserFile /etc/apache2/other/htpasswd-git
    AuthGroupFile /etc/apache2/other/htgroup-git
   <Limit GET>
    Require group myproject-reader
   </Limit>
   <Limit GET PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
    Require group myproject-writer
   </Limit>
     </LocationMatch>
</VirtualHost>

I've changed /etc/hosts to add ciserver.smt as pointing into 127.0.0.1 Now I'm unable to make this request:

git clone http://username@ciserver.smt/ci_test.git

I'm getting:

error: The requested URL returned error: 403 while accessing http://username@ciserver.smt/ci_test.git/info/refs

fatal: HTTP request failed

What did I still do wrong?


Solution

  • It seems that you can't run hooks on a webdav shared repo. But you can use the smart HTTP protocol (which is included into the web server via CGI), which does handle hooks.

    See http://dev.bazingaweb.fr/2011/02/23/how-to-set-up-git-over-http.html for more details.