Skip to content

Instantly share code, notes, and snippets.

@Tlaloc-Es
Forked from chadmaughan/pre-commit.sh
Last active April 21, 2019 11:19
Show Gist options
  • Save Tlaloc-Es/1bd3be9df92febf540608e87f87a248f to your computer and use it in GitHub Desktop.
Save Tlaloc-Es/1bd3be9df92febf540608e87f87a248f to your computer and use it in GitHub Desktop.
A git pre commit hook that runs the test task with the gradle wrapper
#!/bin/sh
# this hook is in SCM so that it can be shared
# to install it, create a symbolic link in the projects .git/hooks folder
#
# i.e. - from the .git/hooks directory, run
# $ ln -s ../../git-hooks/pre-commit.sh pre-commit
#
# to skip the tests, run with the --no-verify argument
# i.e. - $ 'git commit --no-verify'
# stash any unstaged changes
git stash -q --keep-index
# run the lintern with the gradle wrapper
./gradlew lint
# store the last exit code in a variable
RESULT=$?
# unstash the unstashed changes
git stash pop -q
# return the './gradlew test' exit code
exit $RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment