Created
January 25, 2018 15:35
pre-commit hook for sqlinter
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
if [[ ! $(which gem) ]]; then | |
echo "You don't have gem installed. Go install it." | |
exit 1 | |
fi | |
if [[ ! $(which sqlint) ]]; then | |
gem install sqlint | |
fi | |
git diff --cached --name-status | xargs -0 | while read st file; do | |
# skip deleted files | |
if [ "$st" == 'D' ]; then continue; fi | |
# do a check only on the sql files | |
if [[ ! $file =~ .sql$ ]]; then continue; fi | |
res=$(sqlint $file) | |
exitCode=$? | |
if [[ exitCode != 0 ]]; then | |
echo $res | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment