阻止Git存储库中某些用户的特定文件 [英] block specific file for some users in Git repository

查看:217
本文介绍了阻止Git存储库中某些用户的特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,有一个css样式文件,这个文件不应该被开发团队中的任何人修改,只有管理员(我):)

有什么办法来锁定文件。我在提交中看到,该文件已被更改,但我不希望发生这种情况。



我可以做什么?



我使用gitblit服务器,而git使用git-extensions。



非常感谢您的回答。

解决方案

这必须在服务器上完成,通过在Gitblit中设置一个钩子。检查提供的一个接收后挂接。在收到推送数据后,服务器会运行post-receive挂钩,如果它返回false,推送将被拒绝。



当脚本被调用时你会得到一个refs列表,参见示例中的如何获取提交列表



这应该让您开始获取推送中包含的文件列表:


$ b

  def commits = JGitUtils.getRevLog(repository,command.oldId.name,command.newId。 name)
提交提交:
def diffs = git.diff()。setNewTree(commit.getTree())
.setOldTree(commit.getParent(0).getTree())
.call();
用于比较差异:
def path = diff.getOldPath();
//检查路径中的扩展名,并返回false以拒绝推送


I have a problem, there is a css style file, this file should not be modified by anyone from the development team, only the administrator (me) :)

There any way to lock the file. I have seen in the commits, that the file has been changed, but I do not want this to happen.

What I can do?

I use gitblit server, and git with git-extensions.

thank you very much for your answers.

解决方案

This must be done on the server, by setup a hook within Gitblit. Check one of the provided post-receive hooks. A post-receive hook is run by the server after the push data has been received, and if it returns false the push will be rejected.

When the script will get invoked you get a list of refs, see in the example how to get the list of commits

This should get you started to get a list of the files contained in the push:

def commits = JGitUtils.getRevLog(repository, command.oldId.name, command.newId.name)    
for commit in commits:
     def diffs = git.diff().setNewTree(commit.getTree())
                           .setOldTree(commit.getParent(0).getTree())
                           .call();
     for diff in diffs:
          def path = diff.getOldPath();
          //check the extension on the path, and return false to reject the push

这篇关于阻止Git存储库中某些用户的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆