我正在尝试设置一个 git hook 来禁止任何人删除master
, alpha
, and beta
我们存储库的分支。有人能帮忙吗?我从来没有做过 git hook,所以我不想在没有一点帮助的情况下尝试自己开发自己的 git hook。
直接用一个pre-receive
钩。假设您使用的是裸露的中央存储库,请将以下代码放入your-repo.git/hooks/pre-receive
,并且不要忘记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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)