devhub-tud / Java-Gitolite-Manager

The java-gitolite-manager is a simple and compact Java library which enables developers to manage their gitolite configuration from Java. The aim is to give developers an easy to understand interface to manage repositories, groups and users in gitolite.
Apache License 2.0
11 stars 5 forks source link

Ability to add/remove git hooks #9

Open michaeldejong opened 11 years ago

michaeldejong commented 11 years ago

Users should be able to add or remove git hooks for every repository (excluding gitolite-admin). This will probably require Java-Gitolite-Manager to be run on the git server (preferably on the git user).

michaeldejong commented 11 years ago

I've been trying to figure out how to write a post-update hook so I'll be able to notify a HTTP server.

#!/usr/bin/perl -w

use strict;
use warnings;

use lib $ENV{GL_LIBDIR};
use Gitolite::Hooks::Update

# gitolite update hook
#---------------------------------------------------------------

my $path = `pwd`;
$path =~ s/\/home\/git\/repositories\///;
`curl -s http://<host>/?repo=$path`;

update();
exit 1;
alexnederlof commented 11 years ago

Why PERL? All variables are passed in a hook.

It takes a variable number of parameters, each of which is the name of ref that was actually updated.

https://www.kernel.org/pub/software/scm/git/docs/githooks.html

You can use CURL to do form a POST body in Json and deliver that to a webserver.

REVISION=$2  # or whatever it is
curl -X POST -H "Content-Type: application/json" -d '{"revision":"$REVISION","repo":"xyz"}' http://the.url.com/hook
michaeldejong commented 11 years ago

Perl because, that's what Gitolite is using in the already existing post-update hook of my testing repo. I can easily switch to bash, but for now it's just to find out how these hooks work and test them. Also, my current aim is just to be able to notify a web server that a certain repository has received a push. It's up to that web server to determine if it's interested in fetching stuff like logs/diffs/branches.