5 # setup repo-specific hooks
7 use lib
$ENV{GL_LIBDIR
};
11 _die
"repo-specific-hooks: LOCAL_CODE not defined in rc" unless $rc{LOCAL_CODE
};
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 );
30 my ( $repo, $hook, $codes ) = split /\t/, $_;
34 $hook =~ s/^gitolite-options\.hook\.//;
37 # this is a special case
38 if ( $repo eq 'gitolite-admin' and $hook eq 'post-update' ) {
39 _warn
"repo-specific-hooks: ignoring attempts to set post-update hook for the admin repo";
43 unless ( $hook =~ /^(pre-receive|post-receive|post-update)$/ ) {
44 _warn
"repo-specific-hooks: '$hook' is not allowed, ignoring";
45 _warn
" (only pre-receive, post-receive, and post-update are allowed)";
49 my @codes = split /\s+/, $codes;
50 push @
{ $repo_hooks{$repo}{$hook} }, @codes if @codes;
53 for my $repo (keys %repo_hooks) {
54 for my $hook (keys %{ $repo_hooks{$repo} }) {
55 my @codes = @
{ $repo_hooks{$repo}{$hook} };
57 my $dst = "$repo.git/hooks/$hook";
58 unlink( glob("$dst.*") );
61 foreach my $code (@codes) {
62 if ( $code =~ m
(^/|\
.\
.) ) {
63 _warn
"repo-specific-hooks: double dot or leading slash not allowed in '$code'";
67 my $src = $rc{LOCAL_CODE
} . "/hooks/repo-specific/$code";
68 my $dst = "$repo.git/hooks/$hook.$counter-$code";
70 _warn
"repo-specific-hooks: '$src' doesn't exist or is not executable";
74 symlink $src, $dst or _warn
"could not symlink '$src' to '$dst'";
77 # no sanity checks for multiple overwrites of the same hook
81 symlink $driver, $dst or die "could not symlink '$driver' to '$dst'";
88 # Determine what input the hook needs
89 # post-update takes args, pre/post-receive take stdin
92 [ $0 != hooks
/post
-update
] && {