ファイルが変更されたかどうかを確認するための単純な pre-commit フックを作成しようとしています。変更されている場合は、圧縮して現在のインデックスに追加します。
#!/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
私には 2 つの問題があります。これは私が返すエラーです:
[: 23: git: unexpected operator
そして私の2番目の問題は、条件を削除しても、ファイルが実際にはコミットに追加されず、変更されても追加されないことです。
ありがとう、レオ