Skip to content

Instantly share code, notes, and snippets.

@yvmarques
Last active December 19, 2015 13:49
Show Gist options
  • Save yvmarques/5965197 to your computer and use it in GitHub Desktop.
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
#!/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