Last active
August 29, 2015 13:55
-
-
Save sergeylukin/8707344 to your computer and use it in GitHub Desktop.
git hook that sets flags according to modified files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while read oldrev newrev refname | |
do | |
COMPILE_JAVASCRIPTS=0 | |
COMPILE_IMAGES=0 | |
COMPILE_STYLESHEETS=0 | |
for file in `git diff $oldrev $newrev --name-only`; do | |
if [ `echo $file | cut -c 1-22` == "app/assets/javascripts" \ | |
-o \ | |
`echo $file | cut -c 1-25` == "shared/assets/javascripts" \ | |
]; then | |
COMPILE_JAVASCRIPTS=1 | |
fi | |
if [ `echo $file | cut -c 1-17` == "app/assets/images" \ | |
-o \ | |
`echo $file | cut -c 1-20` == "shared/assets/images" \ | |
]; then | |
COMPILE_IMAGES=1 | |
fi | |
if [ `echo $file | cut -c 1-22` == "app/assets/stylesheets" \ | |
-o \ | |
`echo $file | cut -c 1-25` == "shared/assets/stylesheets" \ | |
]; then | |
COMPILE_STYLESHEETS=1 | |
fi | |
done | |
# Build options | |
OPTIONS="--production" | |
if [ $COMPILE_JAVASCRIPTS == 1 ]; then | |
OPTIONS="$OPTIONS --javascripts" | |
fi | |
if [ $COMPILE_IMAGES == 1 ]; then | |
OPTIONS="$OPTIONS --images" | |
fi | |
if [ $COMPILE_STYLESHEETS == 1 ]; then | |
OPTIONS="$OPTIONS --stylesheets" | |
fi | |
echo "OPTIONS: $OPTIONS" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment