~ubuntu-branches/ubuntu/vivid/gitolite3/vivid-proposed

« back to all changes in this revision

Viewing changes to src/triggers/repo-specific-hooks

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2014-05-25 20:09:36 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140525200936-el6hezd1fym50pxh
Tags: 3.6-1
* New upstream release
* Depend on ssh-server instead of openssh-server (Closes: #735176).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
# setup repo-specific hooks
6
6
 
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
10
 
 
11
7
use lib $ENV{GL_LIBDIR};
12
8
use Gitolite::Rc;
13
9
use Gitolite::Common;
14
10
 
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};
17
 
 
18
 
_chdir($ENV{GL_REPO_BASE});
19
 
 
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";
 
13
 
 
14
_chdir( $ENV{GL_REPO_BASE} );
 
15
 
 
16
@ARGV = ("gitolite list-phy-repos | gitolite git-config -ev -r % gitolite-options\\.hook\\. |");
 
17
 
 
18
my $driver = "$rc{LOCAL_CODE}/hooks/multi-hook-driver";
 
19
# Hook Driver
 
20
{
 
21
    local $/ = undef;
 
22
    my $hook_text = <DATA>;
 
23
    _print( $driver, $hook_text );
 
24
    chmod 0755, $driver;
 
25
}
21
26
 
22
27
while (<>) {
23
28
    chomp;
24
 
    my ($repo, $hook, $code) = split /\t/, $_;
 
29
    my ( $repo, $hook, $codes ) = split /\t/, $_;
 
30
    $codes ||= '';
25
31
 
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";
29
35
        next;
30
36
    }
32
38
    # get the hook name
33
39
    $hook =~ s/^gitolite-options\.hook\.//;
34
40
 
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";
37
43
        next;
38
44
    }
39
45
 
40
 
    if ($code =~ m(^/|\.\.)) {
41
 
        _warn "repo-specific-hooks: double dot or leading slash not allowed in '$code'";
42
 
        next;
43
 
    }
 
46
    my @codes = split /\s+/, $codes;
44
47
 
45
 
    my $src = $rc{LOCAL_CODE} . "/hooks/repo-specific/$code";
46
48
    my $dst = "$repo.git/hooks/$hook";
47
 
    unless (-x $src) {
48
 
        _warn "repo-specific-hooks: '$src' doesn't exist or is not executable";
49
 
        next;
 
49
    unlink( glob("$dst.*") );
 
50
 
 
51
    my $counter = "h00";
 
52
    foreach my $code (@codes) {
 
53
        if ( $code =~ m(^/|\.\.) ) {
 
54
            _warn "repo-specific-hooks: double dot or leading slash not allowed in '$code'";
 
55
            next;
 
56
        }
 
57
 
 
58
        my $src = $rc{LOCAL_CODE} . "/hooks/repo-specific/$code";
 
59
        my $dst = "$repo.git/hooks/$hook.$counter-$code";
 
60
        unless ( -x $src ) {
 
61
            _warn "repo-specific-hooks: '$src' doesn't exist or is not executable";
 
62
            next;
 
63
        }
 
64
        unlink $dst;
 
65
        symlink $src, $dst or _warn "could not symlink '$src' to '$dst'";
 
66
        $counter++;
 
67
 
 
68
        # no sanity checks for multiple overwrites of the same hook
50
69
    }
 
70
 
51
71
    unlink $dst;
52
 
    symlink $src, $dst or _warn "could not symlink '$src' to '$dst'";
53
 
    # no sanity checks for multiple overwrites of the same hook
54
 
}
 
72
    symlink $driver, $dst or die "could not symlink '$driver' to '$dst'";
 
73
}
 
74
 
 
75
__DATA__
 
76
#/bin/sh
 
77
 
 
78
# Determine what input the hook needs
 
79
# post-update takes args, pre/post-receive take stdin
 
80
type=args
 
81
stdin=''
 
82
[ $0 != hooks/post-update ] && {
 
83
    type=stdin
 
84
    stdin=`cat`
 
85
}
 
86
 
 
87
for h in $0.*; do
 
88
    [ -x $h ] || continue
 
89
    if [ $type = args ]
 
90
    then
 
91
        $h $@
 
92
    else
 
93
        echo "$stdin" | $h
 
94
    fi
 
95
done