gitolite/Gitolite/Hooks/PostUpdate.pm
Sitaram Chamarty 8ffc5307d6 (lotsa files affected) rc file format changed; see below
The rc file used to be a bunch of variables, each one requiring to be
declared before being used.  While this was nice and all, it was a
little cumbersome to add a new flag or option.

If you disregard the "catch typos" aspect of having to predeclare
variables, it's a lot more useful to have all of rc be in a hash and use
any hash keys you want.

There could be other uses; for instance it could hold arbitrary data
that you would currently put in %ENV, without having to pollute %ENV if
you don't need child tasks to inherit it.

----

NOTE: I also ran perltidy, which I don't always remember to :)
2012-03-24 10:30:41 +05:30

70 lines
1.4 KiB
Perl

package Gitolite::Hooks::PostUpdate;
# everything to do with the post-update hook
# ----------------------------------------------------------------------
@EXPORT = qw(
post_update
post_update_hook
);
use Exporter 'import';
use lib $ENV{GL_BINDIR};
use Gitolite::Rc;
use Gitolite::Common;
use strict;
use warnings;
# ----------------------------------------------------------------------
sub post_update {
trace(3);
# this is the *real* post_update hook for gitolite
tsh_try("git ls-tree --name-only master");
_die "no files/dirs called 'hooks' or 'logs' are allowed" if tsh_text() =~ /^(hooks|logs)$/;
{
local $ENV{GIT_WORK_TREE} = $rc{GL_ADMIN_BASE};
tsh_try("git checkout -f --quiet master");
}
system("$ENV{GL_BINDIR}/gitolite compile");
exit 0;
}
{
my $text = '';
sub post_update_hook {
trace(1);
if ( not $text ) {
local $/ = undef;
$text = <DATA>;
}
return $text;
}
}
1;
__DATA__
#!/usr/bin/perl
use strict;
use warnings;
BEGIN {
die "GL_BINDIR not set; aborting\n" unless $ENV{GL_BINDIR};
}
use lib $ENV{GL_BINDIR};
use Gitolite::Hooks::PostUpdate;
# gitolite post-update hook (only for the admin repo)
# ----------------------------------------------------------------------
post_update(@ARGV); # is not expected to return
exit 1; # so if it does, something is wrong