Preventing the user from modifying the .gitignore file?
With Gitolite , the pre-receive Hooks are called VREFS ( Virtual Links , also here) : don Don't set the pre-receive bind directly in gitolite managed repositories, do it by adding the VREF to the VREF
repo directory gitolite-admin
and Gitolite will distribute it to the repository.
The section " Limiting clicks on a dir / file name " illustrates how to restrict clicks on file and file names. > This is one of the VREFs that you don't need to add to the directory VREF
, in fact (it is part of the update hook managed by Gitolite. For additional update binding see here ).
So changing gitolite.conf
in the repo gitolite-admin
and pushing back the admin repository to the gitolite server is enough.
repo foo
RW+ = @senior_devs
RW = @junior_devs
- VREF/NAME/Makefile = @junior_devs
source to share
Git is decentralized. When someone cloned a repo, it is completely under their control, including the file .gitignore
.
What you can do is prevent users from pushing certain files to your server using a Git hook that checks the specified file types and refuses the user to push.
Read the preliminary approvals . And write a script that looks for the specified file types.
Check your repo .git/hooks
, there will be a list of example files that will show you how to handle it. Also read this article to avoid an easy mistake.
EDIT
I'm not very good with shell scripting, but here's a small script that disallows .php and .css files and informs the user before canceling. It is located in .git/hooks/pre-receive
. Don't forget to make it executable ( chmod +x
), otherwise it won't work.
#!/bin/sh
while read oldrev newrev refname
do
if [[ `git diff-tree --no-commit-id --name-only -r $newrev | grep -e 'css\|php'` != "" ]]
do
echo "Cannot push this"
exit 1;
fi
end
source to share