Last active
December 19, 2015 13:49
-
-
Save yvmarques/5965197 to your computer and use it in GitHub Desktop.
pre-commit hook to run the grunt release to ensure that all files static are also committed (runs only if js,less or css have been changed). I assume that all the generated files are stored in static's folder
This file contains 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
#!/bin/sh | |
# stash unstaged changes, run release task, stage release updates and restore stashed files | |
PATH=$PATH:/usr/local/bin:/usr/local/sbin | |
NAME=$(git branch | grep '*' | sed 's/* //') | |
# Run the commit only if we have css,less or js files changed | |
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E "\.(js|less|css)$") | |
if [ "$files" = "" ] | |
then | |
exit 0 | |
fi | |
# don't run on rebase | |
if [ $NAME != '(no branch)' ] | |
then | |
# first we discard the changes into static | |
# as it will be generated by grunt just below | |
git checkout static && git stash -q --keep-index | |
grunt --no-color release | |
RETVAL=$? | |
if [ $RETVAL -ne 0 ] | |
then | |
git stash pop -q | |
exit 1 | |
fi | |
# Only add files that are into static | |
git add static | |
git stash pop -q | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment