Month: September 2009

git commit 前幫 js&css打timestamp

Posted by – 2009-09-10

建立.git/hooks/pre-commit 檔案內容如下

#!/bin/bash
setFileTimestampByType()
{
type=$1
for targetFile in `git diff –name-only HEAD`;
do
targetFile=`echo $targetFile | grep -e "${type}\$" `
if [ "$targetFile" != ];
then
timestamp=`date +%s`
targetFileBaseName=`basename $targetFile`
i=0
for viewFile in `grep -l -R $targetFileBaseName view`;
do
if [ $i -eq 0 ] ;
then
echo "set $targetFile timestamp"
i=1
fi
echo "    $viewFile…done"
sed  -i -e "s/\(${targetFileBaseName}\)[^\"']*/\1?date=${timestamp}/g" $viewFile
done
fi
done
}
setFileTimestampByType ‘js’
setFileTimestampByType ‘css’