Skip to content

Instantly share code, notes, and snippets.

@connesc
Last active August 29, 2015 14:21
Show Gist options
  • Save connesc/50257ea06c6b04b18cc6 to your computer and use it in GitHub Desktop.
Save connesc/50257ea06c6b04b18cc6 to your computer and use it in GitHub Desktop.
Git pre-commit hook for launching a test suite
#!/bin/sh
# Clean the working tree if needed
before="$(git rev-parse --verify --quiet refs/stash)"
git stash save --keep-index --include-untracked --quiet 'Git pre-commit hook'
after="$(git rev-parse --verify --quiet refs/stash)"
# Run tests
grunt jshint
status=$?
# Restore the working tree if needed
if [ "$after" != "$before" ]
then
git reset --hard --quiet
git stash pop --index --quiet
fi
# Exit with the relevant status
exit $status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment