Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Forked from chadmaughan/pre-commit.sh
Last active February 12, 2016 04:22
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 danielgomezrico/f4cac103a3f95f417e60 to your computer and use it in GitHub Desktop.
Save danielgomezrico/f4cac103a3f95f417e60 to your computer and use it in GitHub Desktop.
A git pre commit hook that runs the test task with the gradle wrapper
#!/usr/bin/env bash
# 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
ABSOLUTE_PATH=$(cd `dirname "${BASH_SOURCE[0]}"`)
ABSOLUTE_PARENT_PATH="$(dirname "$ABSOLUTE_PATH")"
# run the tests with the gradle wrapper
sh $ABSOLUTE_PARENT_PATH/gradlew testMockedDebug testMockedRelease --daemon
# 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
@danielgomezrico
Copy link
Author

Updated to allow it to be inside the project in other folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment