Last active
November 19, 2015 16:45
-
-
Save rxaviers/a5cb35e756b1e54d18d9 to your computer and use it in GitHub Desktop.
git pre-push hook to unit test code before pushing to master branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
IFS=' ' | |
z40=0000000000000000000000000000000000000000 | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
remote_abbrev_ref=$(echo $remote_ref | cut -d/ -f3) | |
if [ :$remote_abbrev_ref != :master ]; then | |
exit 0 | |
fi | |
if [ :local_sha = :z40 ]; then | |
exit 0 | |
fi | |
current_sha1=$(git rev-parse HEAD) | |
echo local_sha $local_sha | |
echo current_sha1 $current_sha1 | |
if [ :$local_sha != :$current_sha1 ]; then | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
git checkout $local_sha | |
fi | |
npm test | |
S=$? | |
if [ :$local_sha != :$current_sha1 ]; then | |
git checkout $current_branch | |
fi | |
done | |
exit $S |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment