Skip to content

Instantly share code, notes, and snippets.

@sergeylukin
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeylukin/8707344 to your computer and use it in GitHub Desktop.
Save sergeylukin/8707344 to your computer and use it in GitHub Desktop.
git hook that sets flags according to modified files
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