Created
September 21, 2016 00:38
-
-
Save thejonanshow/8d27dd1164baf2a904ed490150b04234 to your computer and use it in GitHub Desktop.
Git pre-push hook to check that specs have been run.
This file contains 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 | |
# Pre-push check that specs have been run against HEAD. | |
# ignore projects that don't have a spec directory and spec_helper | |
if [[ -e "spec" && -e "spec/spec_helper.rb" ]]; then | |
if grep -Fxq "# Write .spec_sha for pre-push hook" spec/spec_helper.rb; then | |
local_sha="`git log -n 1 --pretty=format:%H`" | |
# if the .spec_sha file doesn't exist or the sha doesn't match run rake | |
if ! [[ -e ".spec_sha" && "$local_sha" == `cat .spec_sha` ]]; then | |
echo "Specs have not been run since the last commit, running specs with 'rake'." | |
rake | |
exit $? | |
fi | |
else | |
# prepend a line to spec_helper.rb that writes the .spec_sha file | |
echo "Adding code to spec_helper to write the .spec_sha file." | |
echo "File.write('.spec_sha', %x[git log -n 1 --pretty=format:%H])" | cat - spec/spec_helper.rb > /tmp/out && mv /tmp/out spec/spec_helper.rb | |
echo "# Write .spec_sha for pre-push hook" | cat - spec/spec_helper.rb > /tmp/out && mv /tmp/out spec/spec_helper.rb | |
exit 1 | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment