I'm a git newbie suffering from prior svn experience. Many of my projects are using code from my own libraries, so naturally I want some "externals-like" functionality from git. I'm currently trying to use submodules.
But submodules (as far as I understand) can provide a lot of pain if you use them in the wrong way (for example, change files in submodule and forget to push them, or forget to commit them).
What if I make all files in submodule read-only? That's a good enough protection from accidental change. And if I really want to change something I should go and make that change in the original repo.
So, my question is:
- Is that a good idea or I'm trying to reinvent the wheel?
- What's the easiest way to do it?
EDIT: I hope that could be achieved with git hooks, but I'm not sure how exactly. I can't use client hooks when cloning the repo for the first time, can I?
EDIT2: With help of SRobertz I was able to come up with a post-checkout hook:
echo "you just checked out: $*"
echo "submodules:"
for p in `grep path .gitmodules | sed 's/.*= //'`; do # get submodules list
echo "making submodule directory $p read-only"
chmod -R a-w $p;
SAVEIFS=$IFS
IFS=$(echo -en "\n\b") #set delimeter to \n\b to handle whitespaces in filenames
for f in `ls $p`; do #get files in submodule dir
echo "making file $f in directory $p read-only"
chmod -R a-w $p\\$f;
done
IFS=$SAVEIFS #restore delimeter to default value
done
Now the problem is that when cloning a new repo, this hook fires too early, when submodule directories are already created but files in them are not pulled yet.