Skip to content

Instantly share code, notes, and snippets.

@kaskavalci
Created January 25, 2018 15:35
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 kaskavalci/77fc86b79de0b81922adb589466f17ff to your computer and use it in GitHub Desktop.
Save kaskavalci/77fc86b79de0b81922adb589466f17ff to your computer and use it in GitHub Desktop.
pre-commit hook for sqlinter
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