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 if ($ARGV[0] eq 'POST_CREATE') {
17 # just the repo given in arg-2
18 @ARGV = ("gitolite git-config -ev -r $ARGV[1] gitolite-options\\.hook\\. |");
20 # POST_COMPILE, all repos
21 @ARGV = ("gitolite list-phy-repos | gitolite git-config -ev -r % gitolite-options\\.hook\\. |");
24 my $driver = $rc{MULTI_HOOK_DRIVER
} || "$rc{LOCAL_CODE}/hooks/multi-hook-driver";
28 my $hook_text = <DATA
>;
29 _print
( $driver, $hook_text );
36 my ( $repo, $hook, $codes ) = split /\t/, $_;
40 $hook =~ s/^gitolite-options\.hook\.//;
43 my @codes = split /\s+/, $codes;
46 # this is a special case
47 if ( $repo eq 'gitolite-admin' and $hook eq 'post-update' ) {
48 _warn
"repo-specific-hooks: ignoring attempts to set post-update hook for the admin repo";
52 unless ( $hook =~ /^(pre-receive|post-receive|post-update|pre-auto-gc)$/ ) {
53 _warn
"repo-specific-hooks: '$hook' is not allowed, ignoring";
54 _warn
" (only pre-receive, post-receive, post-update, and pre-auto-gc are allowed)";
58 push @
{ $repo_hooks{$repo}{$hook} }, @codes if @codes;
61 for my $repo (keys %repo_hooks) {
62 for my $hook (keys %{ $repo_hooks{$repo} }) {
63 my @codes = @
{ $repo_hooks{$repo}{$hook} };
65 my $dst = "$repo.git/hooks/$hook";
66 unlink( glob("$dst.*") );
69 foreach my $code (@codes) {
70 if ( $code =~ m
(^/|\
.\
.) ) {
71 _warn
"repo-specific-hooks: double dot or leading slash not allowed in '$code'";
75 my $src = $rc{LOCAL_CODE
} . "/hooks/repo-specific/$code";
77 # if $code has slashes in it, flatten it for use in $dst, to avoid
78 # having to re-create those intermediate sub-directories
80 my $dst = "$repo.git/hooks/$hook.$counter-$code";
83 _warn
"repo-specific-hooks: '$src' doesn't exist or is not executable";
87 symlink $src, $dst or _warn
"could not symlink '$src' to '$dst'";
90 # no sanity checks for multiple overwrites of the same hook
94 symlink $driver, $dst or die "could not symlink '$driver' to '$dst'";
101 # Determine what input the hook needs
102 # post-update takes args, pre/post-receive take stdin
105 [ $0 != hooks
/post
-update
] && {
111 [ -x
$h ] || continue
114 $h $@
|| { [ $0 = hooks
/pre
-receive
] && exit 1; }
116 echo
"$stdin" | $h || { [ $0 = hooks
/pre
-receive
] && exit 1; }