Skip to content

Instantly share code, notes, and snippets.

@polbins
Last active Oct 3, 2018
Embed
What would you like to do?
Pre-push to run your lint and tests
#!/bin/bash
# Installation
# ============
# 1. Add this snippet to: `<REPO>/.git/hooks/pre-push`
# 2. Make sure to `chmod a+x <REPO>/.git/hooks/pre-push` to make the code executable
# Check if we actually have commits to push
commits=`git log @{u}..`
if [ -z "$commits" ]; then
echo "no commits to push. aborting check..."
exit 0
fi
LINT_CMD="gradle ktlint" # Command that runs your lint
$LINT_CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "failed lint check '$LINT_CMD'"
exit 1
fi
TEST_CMD="gradle app:testAlphaDebug" # Command that runs your tests
$TEST_CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "failed tests check '$TEST_CMD'"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment