Perl   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了perl – 不允许在git中删除Master分支大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试设置一个git钩子,禁止任何人删除我们的存储库的master,alpha和beta分支.有人能帮忙吗?我从来没有做过一个git hook,所以我不想在没有一点帮助的情况下尝试自己开发自己的运气.

提前致谢.

解决方法

直接使用预接收挂钩.假设您正在使用裸中央存储库,请将以下代码放在您的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;

大佬总结

以上是大佬教程为你收集整理的perl – 不允许在git中删除Master分支全部内容,希望文章能够帮你解决perl – 不允许在git中删除Master分支所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。