Directo con un gancho pre-receive
. Suponiendo que está utilizando un repositorio central desnudo, coloque el siguiente código en your-repo.git/hooks/pre-receive
, y no se olvide de chmod +x your-repo.git/hooks/pre-receive
.
#! /usr/bin/perl
# create: 00000... 51b8d... refs/heads/topic/gbacon
# delete: 51b8d... 00000... refs/heads/topic/gbacon
# update: 51b8d... d5e14... refs/heads/topic/gbacon
my $errors = 0;
while (<>) {
chomp;
next
unless m[^
([0-9a-f]+) # old SHA-1
\s+
([0-9a-f]+) # new SHA-1
\s+
refs/heads/(\S+) # ref
\s*
$
]x;
my($old,$new,$ref) = ($1,$2,$3);
next unless $ref =~ /^(master|alpha|beta)$/;
die "$0: deleting $ref not permitted!\n"
if $new =~ /^0+$/;
}
exit $errors == 0 ? 0 : 1;