I'm trying to write a simple pre-commit hook to check if a file was modified, if so, compress it and add it into the current index, something like this
#!/bin/sh
# was the file modified?
mf='git status | grep jquery.detectBrowser.js'
# is the non-compressed file in the staging area?
if [ $mf != "" ]
then
# alert the user
echo "Javascript file modified, YUI Compressor will begin now."
# go to rhino
cd $HOME/apps/rhino/yuicompressor-2.4.7/build
# compress my file
java -jar yuicompressor-2.4.7.jar ~/www/jquery.detectBrowser.js/jquery.detectBrowser.js -o ~/www/jquery.detectBrowser.js/jquery.detectBrowser.min.js
# comeback to the initial directory
cd -
# add the new file into the index
git add ~/www/jquery.detectBrowser.js/jquery.detectBrowser.min.js
fi
I have 2 issues, 1 my condition is failing, every time, I must have a typo or something like that, but I can't figure out what it is? This is the error I get back:
[: 23: git: unexpected operator
And my second problem is that even if I remove the condition the file is never actually ADDED into the commit, it's modified, but never ADDED.
Thanks, Leo