3

Is there any why to force user not to change .gitignore file. What I mean is let's say that someone will change or delete this file and push this changes.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
Marceli Po
  • 733
  • 1
  • 7
  • 24

3 Answers3

4

With Gitolite, pre-receive Hooks are called VREFS (Virtual Refs, also listed here): don't setup a pre-receive hook directly in repos managed by gitolite, do it by adding a VREF in the VREF directory of the gitolite-admin repo, and Gitolite will propagate it to the repos.

The section "restricting pushes by dir/file name" illustrates how to restrict pushes by the names of dirs and files changed.
That is one VREF you don't need to add to the VREF directory, actually (it is part of the update hook managed by Gitolite. For secondary update hook, see here).

So modifying the gitolite.conf in the gitolite-admin repo, and pushing back that admin repo to the gitolite server is enough.

repo foo
        RW+                             =   @senior_devs
        RW                              =   @junior_devs

        -   VREF/NAME/Makefile          =   @junior_devs
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This is pretty cool and it's working like a charm :P Thx very much. I have also another question a bit off topic can you advise me a good work flow using GIT with QA team and code reviewer in environment with development, testing, staging and production servers? – Marceli Po Feb 15 '13 at 10:55
  • @MarceliPo The git-flow is the current standard, and is a good starting point (http://stackoverflow.com/a/12927985/6309) – VonC Feb 15 '13 at 14:20
  • @MarceliPo, If this answered your question, can you mark it as the correct answer so that others visiting will know, and VonC will receive proper attribution? :) – Swivel Oct 10 '13 at 16:34
3

Git is decentralised. Once someone has cloned a repo, it is entirely under their control, including the .gitignore file.

What you can do is prevent users to push certain files to your server by using a Git hook that checks for the specified file types and refuses the user to push.

Read up on pre-receive hooks. And write a script that searches for the given file types.

Check your repo .git/hooks there will be a list of sample files that show you how to handle it. Also read this article to avoid an easy mistake to make.

EDIT

I'm not any good at shell scripting, but here's a small script that disallows .php and .css files and tells the user before aborting. It's located in .git/hooks/pre-receive. Remember to make it executable (chmod +x) or else 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
Jørgen R
  • 10,568
  • 7
  • 42
  • 59
2

You can set a pre-receive hook on the server side, and refuse the push if .gitignore is modified.

CharlesB
  • 86,532
  • 28
  • 194
  • 218