block specific file for some users in Git repository

左心房为你撑大大i 提交于 2019-12-11 19:24:54

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/17866246/block-specific-file-for-some-users-in-git-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!