5
5
# setup repo-specific hooks
7
# code is too long, but if you take out all the error/safety/sanity checks,
8
# it's basically just creating a symlink in <repo.git>/hooks pointing to some
9
# file inside $rc{LOCAL_CODE}/hooks/repo-specific
11
7
use lib $ENV{GL_LIBDIR};
13
9
use Gitolite::Common;
15
11
_die "repo-specific-hooks: LOCAL_CODE not defined in rc" unless $rc{LOCAL_CODE};
16
_die "repo-specific-hooks: '$rc{LOCAL_CODE}' does not exist or is not a directory" unless -d $rc{LOCAL_CODE};
18
_chdir($ENV{GL_REPO_BASE});
20
@ARGV = ("gitolite list-phy-repos | gitolite git-config -r % gitolite-options\\.hook\\. |");
12
_die "repo-specific-hooks: '$rc{LOCAL_CODE}/hooks/repo-specific' does not exist or is not a directory" unless -d "$rc{LOCAL_CODE}/hooks/repo-specific";
14
_chdir( $ENV{GL_REPO_BASE} );
16
@ARGV = ("gitolite list-phy-repos | gitolite git-config -ev -r % gitolite-options\\.hook\\. |");
18
my $driver = "$rc{LOCAL_CODE}/hooks/multi-hook-driver";
22
my $hook_text = <DATA>;
23
_print( $driver, $hook_text );
24
my ($repo, $hook, $code) = split /\t/, $_;
29
my ( $repo, $hook, $codes ) = split /\t/, $_;
26
32
# we don't allow fiddling with the admin repo
27
if ($repo eq 'gitolite-admin') {
33
if ( $repo eq 'gitolite-admin' ) {
28
34
_warn "repo-specific-hooks: ignoring attempts to set hooks for the admin repo";
32
38
# get the hook name
33
39
$hook =~ s/^gitolite-options\.hook\.//;
35
unless ($hook =~ /^(pre-receive|post-receive|post-update)$/) {
41
unless ( $hook =~ /^(pre-receive|post-receive|post-update)$/ ) {
36
42
_warn "repo-specific-hooks: '$hook' is not one of the 3 hooks allowed, ignoring";
40
if ($code =~ m(^/|\.\.)) {
41
_warn "repo-specific-hooks: double dot or leading slash not allowed in '$code'";
46
my @codes = split /\s+/, $codes;
45
my $src = $rc{LOCAL_CODE} . "/hooks/repo-specific/$code";
46
48
my $dst = "$repo.git/hooks/$hook";
48
_warn "repo-specific-hooks: '$src' doesn't exist or is not executable";
49
unlink( glob("$dst.*") );
52
foreach my $code (@codes) {
53
if ( $code =~ m(^/|\.\.) ) {
54
_warn "repo-specific-hooks: double dot or leading slash not allowed in '$code'";
58
my $src = $rc{LOCAL_CODE} . "/hooks/repo-specific/$code";
59
my $dst = "$repo.git/hooks/$hook.$counter-$code";
61
_warn "repo-specific-hooks: '$src' doesn't exist or is not executable";
65
symlink $src, $dst or _warn "could not symlink '$src' to '$dst'";
68
# no sanity checks for multiple overwrites of the same hook
52
symlink $src, $dst or _warn "could not symlink '$src' to '$dst'";
53
# no sanity checks for multiple overwrites of the same hook
72
symlink $driver, $dst or die "could not symlink '$driver' to '$dst'";
78
# Determine what input the hook needs
79
# post-update takes args, pre/post-receive take stdin
82
[ $0 != hooks/post-update ] && {