aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSitaram Chamarty <sitaram@atc.tcs.com>2015-11-15 17:51:16 +0530
committerSitaram Chamarty <sitaram@atc.tcs.com>2015-11-15 17:52:42 +0530
commit283af66fa0412b400014f1d663b5ae35093e415d (patch)
tree91837d961a01a9646cab67ecc771e4a06acee147
parentadd security warning to 'config' command (diff)
downloadgitolite-gentoo-283af66fa0412b400014f1d663b5ae35093e415d.tar.gz
gitolite-gentoo-283af66fa0412b400014f1d663b5ae35093e415d.tar.bz2
gitolite-gentoo-283af66fa0412b400014f1d663b5ae35093e415d.zip
repo specific hooks:
- allow incrementally adding more repo-specific hooks see https://groups.google.com/forum/#!topic/gitolite/YcfuFDzhq4A - allow gitolite-admin repo also to be "hooked" (but not post-update of course) see https://groups.google.com/forum/#!topic/gitolite/zAi4H1OKkgI
-rwxr-xr-xsrc/triggers/repo-specific-hooks63
-rwxr-xr-xt/repo-specific-hooks.t23
2 files changed, 58 insertions, 28 deletions
diff --git a/src/triggers/repo-specific-hooks b/src/triggers/repo-specific-hooks
index 5d52a47..f8d2690 100755
--- a/src/triggers/repo-specific-hooks
+++ b/src/triggers/repo-specific-hooks
@@ -24,19 +24,21 @@ my $driver = "$rc{LOCAL_CODE}/hooks/multi-hook-driver";
chmod 0755, $driver;
}
+my %repo_hooks;
while (<>) {
chomp;
my ( $repo, $hook, $codes ) = split /\t/, $_;
$codes ||= '';
- # we don't allow fiddling with the admin repo
- if ( $repo eq 'gitolite-admin' ) {
- _warn "repo-specific-hooks: ignoring attempts to set hooks for the admin repo";
- next;
- }
-
# get the hook name
$hook =~ s/^gitolite-options\.hook\.//;
+ $hook =~ s/\..*//;
+
+ # this is a special case
+ if ( $repo eq 'gitolite-admin' and $hook eq 'post-update' ) {
+ _warn "repo-specific-hooks: ignoring attempts to set post-update hook for the admin repo";
+ next;
+ }
unless ( $hook =~ /^(pre-receive|post-receive|post-update)$/ ) {
_warn "repo-specific-hooks: '$hook' is not allowed, ignoring";
@@ -45,32 +47,39 @@ while (<>) {
}
my @codes = split /\s+/, $codes;
+ push @{ $repo_hooks{$repo}{$hook} }, @codes if @codes;
+}
- my $dst = "$repo.git/hooks/$hook";
- unlink( glob("$dst.*") );
-
- my $counter = "h00";
- foreach my $code (@codes) {
- if ( $code =~ m(^/|\.\.) ) {
- _warn "repo-specific-hooks: double dot or leading slash not allowed in '$code'";
- next;
+for my $repo (keys %repo_hooks) {
+ for my $hook (keys %{ $repo_hooks{$repo} }) {
+ my @codes = @{ $repo_hooks{$repo}{$hook} };
+
+ my $dst = "$repo.git/hooks/$hook";
+ unlink( glob("$dst.*") );
+
+ my $counter = "h00";
+ foreach my $code (@codes) {
+ if ( $code =~ m(^/|\.\.) ) {
+ _warn "repo-specific-hooks: double dot or leading slash not allowed in '$code'";
+ next;
+ }
+
+ my $src = $rc{LOCAL_CODE} . "/hooks/repo-specific/$code";
+ my $dst = "$repo.git/hooks/$hook.$counter-$code";
+ unless ( -x $src ) {
+ _warn "repo-specific-hooks: '$src' doesn't exist or is not executable";
+ next;
+ }
+ unlink $dst;
+ symlink $src, $dst or _warn "could not symlink '$src' to '$dst'";
+ $counter++;
+
+ # no sanity checks for multiple overwrites of the same hook
}
- my $src = $rc{LOCAL_CODE} . "/hooks/repo-specific/$code";
- my $dst = "$repo.git/hooks/$hook.$counter-$code";
- unless ( -x $src ) {
- _warn "repo-specific-hooks: '$src' doesn't exist or is not executable";
- next;
- }
unlink $dst;
- symlink $src, $dst or _warn "could not symlink '$src' to '$dst'";
- $counter++;
-
- # no sanity checks for multiple overwrites of the same hook
+ symlink $driver, $dst or die "could not symlink '$driver' to '$dst'";
}
-
- unlink $dst;
- symlink $driver, $dst or die "could not symlink '$driver' to '$dst'";
}
__DATA__
diff --git a/t/repo-specific-hooks.t b/t/repo-specific-hooks.t
index 88976ca..6cacdb2 100755
--- a/t/repo-specific-hooks.t
+++ b/t/repo-specific-hooks.t
@@ -9,7 +9,7 @@ use Gitolite::Test;
# test script for partial copy feature
# ----------------------------------------------------------------------
-try "plan 117";
+try "plan 128";
my $h = $ENV{HOME};
my $rb = `gitolite query-rc -n GL_REPO_BASE`;
@@ -47,6 +47,9 @@ confreset;confadd '
repo baz
RW+ = @all
+
+ repo frob
+ RW+ = @all
';
try "ADMIN_PUSH repo-specific-hooks-0; !/FATAL/" or die text();
@@ -55,6 +58,7 @@ try "
/Init.*empty.*foo\\.git/
/Init.*empty.*bar\\.git/
/Init.*empty.*baz\\.git/
+ /Init.*empty.*frob\\.git/
";
my $failing_hook = "#!/bin/sh
@@ -65,11 +69,13 @@ exit 1
put "$rb/foo.git/hooks/post-recieve", $failing_hook;
put "$rb/bar.git/hooks/pre-recieve", $failing_hook;
put "$rb/baz.git/hooks/post-update", $failing_hook;
+put "$rb/frob.git/hooks/post-update", $failing_hook;
try "# Verify hooks
ls -l $rb/foo.git/hooks/*; ok; !/post-receive -. .*local/hooks/multi-hook-driver/
ls -l $rb/bar.git/hooks/*; ok; !/pre-receive -. .*local/hooks/multi-hook-driver/
ls -l $rb/baz.git/hooks/*; ok; !/post-update -. .*local/hooks/multi-hook-driver/
+ ls -l $rb/frob.git/hooks/*; ok; !/post-update -. .*local/hooks/multi-hook-driver/
";
confreset;confadd '
@@ -85,6 +91,14 @@ confreset;confadd '
RW+ = @all
option hook.post-receive = first
option hook.post-update = first second
+
+ repo frob
+ RW+ = @all
+ option hook.post-receive.b = first
+ option hook.post-receive.a = second
+
+ repo gitolite-admin
+ option hook.post-receive = second
';
@@ -101,6 +115,13 @@ try "# Verify hooks
/post-update.h00-first/
/post-update.h01-second/
/post-update -. .*local/hooks/multi-hook-driver/
+ ls -l $rb/frob.git/hooks/*; ok; /post-receive.h00-second/
+ /post-receive.h01-first/
+ /post-receive -. .*local/hooks/multi-hook-driver/
+ ls -l $rb/gitolite-admin.git/hooks/*
+ ok; /post-receive.h/
+ /post-receive -. .*local/hooks/multi-hook-driver/
+ !/post-update -. .*local/hooks/multi-hook-driver/
";
try "