2009-08-25 05:14:46 +02:00
|
|
|
#!/usr/bin/perl
|
2009-08-23 18:10:03 +02:00
|
|
|
|
|
|
|
use strict;
|
2009-08-25 05:14:46 +02:00
|
|
|
use warnings;
|
2009-08-23 18:10:03 +02:00
|
|
|
|
|
|
|
# === update ===
|
2009-08-26 02:47:27 +02:00
|
|
|
# this is gitolite's update hook
|
2009-08-23 18:10:03 +02:00
|
|
|
|
2009-08-26 02:47:27 +02:00
|
|
|
# part of the gitolite (GL) suite
|
2009-08-23 18:10:03 +02:00
|
|
|
|
|
|
|
# how run: via git, being copied as .git/hooks/update in every repo
|
|
|
|
# when: every push
|
|
|
|
# input:
|
|
|
|
# - see man githooks for STDIN
|
|
|
|
# - uses the compiled config file to get permissions info
|
|
|
|
# output: based on permissions etc., exit 0 or 1
|
|
|
|
# security:
|
|
|
|
# - none
|
|
|
|
|
|
|
|
# robustness:
|
|
|
|
|
|
|
|
# other notes:
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# common definitions
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
|
2009-09-06 10:04:41 +02:00
|
|
|
our ($GL_CONF_COMPILED, $PERSONAL);
|
2009-08-23 18:10:03 +02:00
|
|
|
our %repos;
|
|
|
|
|
2009-08-26 02:47:27 +02:00
|
|
|
my $glrc = $ENV{HOME} . "/.gitolite.rc";
|
2009-09-01 16:06:00 +02:00
|
|
|
die "parse $glrc failed: " . ($! or $@) unless do $glrc;
|
|
|
|
die "parse $GL_CONF_COMPILED failed: " . ($! or $@) unless do $GL_CONF_COMPILED;
|
2009-08-23 18:10:03 +02:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# start...
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
my $ref = shift;
|
|
|
|
my $oldsha = shift;
|
|
|
|
my $newsha = shift;
|
|
|
|
my $merge_base = '0' x 40;
|
2009-08-25 03:08:05 +02:00
|
|
|
# compute a merge-base if both SHAs are non-0, else leave it as '0'x40
|
|
|
|
# (i.e., for branch create or delete, merge_base == '0'x40)
|
2009-08-23 18:10:03 +02:00
|
|
|
chomp($merge_base = `git merge-base $oldsha $newsha`)
|
2009-08-25 03:08:05 +02:00
|
|
|
unless $oldsha eq '0' x 40
|
|
|
|
or $newsha eq '0' x 40;
|
2009-08-23 18:10:03 +02:00
|
|
|
|
|
|
|
# some of this is from an example hook in Documentation/howto of git.git, with
|
|
|
|
# some variations
|
|
|
|
|
|
|
|
# what are you trying to do? (is it 'W' or '+'?)
|
|
|
|
my $perm = 'W';
|
2009-08-25 03:08:05 +02:00
|
|
|
# rewriting a tag is considered a rewind, in terms of permissions
|
2009-08-23 18:10:03 +02:00
|
|
|
$perm = '+' if $ref =~ m(refs/tags/) and $oldsha ne ('0' x 40);
|
2009-08-28 17:11:21 +02:00
|
|
|
# non-ff push to ref
|
|
|
|
# notice that ref delete looks like a rewind, as it should
|
|
|
|
$perm = '+' if $oldsha ne $merge_base;
|
2009-08-23 18:10:03 +02:00
|
|
|
|
2009-08-27 09:44:47 +02:00
|
|
|
my @allowed_refs;
|
2009-08-28 03:46:40 +02:00
|
|
|
push @allowed_refs, @ { $repos{$ENV{GL_REPO}}{$perm}{$ENV{GL_USER}} || [] };
|
|
|
|
push @allowed_refs, @ { $repos{$ENV{GL_REPO}}{$perm}{'@all'} || [] };
|
2009-09-02 03:19:04 +02:00
|
|
|
push @allowed_refs, "$PERSONAL/$ENV{GL_USER}/" if $PERSONAL;
|
2009-08-27 09:44:47 +02:00
|
|
|
for my $refex (@allowed_refs)
|
2009-08-23 18:10:03 +02:00
|
|
|
# refex? sure -- a regex to match a ref against :)
|
|
|
|
{
|
|
|
|
if ($ref =~ /$refex/)
|
|
|
|
{
|
2009-08-25 06:27:19 +02:00
|
|
|
# if log failure isn't important enough to block pushes, get rid of
|
|
|
|
# all the error checking
|
2009-09-06 10:04:41 +02:00
|
|
|
open my $log_fh, ">>", $ENV{GL_LOG}
|
2009-09-10 17:54:58 +02:00
|
|
|
or die "open log failed: $!\n";
|
2009-09-06 10:04:41 +02:00
|
|
|
print $log_fh "$ENV{GL_TS} $perm\t" .
|
|
|
|
substr($oldsha, 0, 14) . "\t" . substr($newsha, 0, 14) .
|
|
|
|
"\t$ENV{GL_REPO}\t$ref\t$ENV{GL_USER}\n";
|
2009-09-10 17:54:58 +02:00
|
|
|
close $log_fh or die "close log failed: $!\n";
|
2009-08-23 18:10:03 +02:00
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit 1;
|