#!/bin/bash lod_message() { cat < /dev/null; fail=$? if [[ "$fail" -ne 0 ]]; then echo "Syntax Error found in '$FILE'"; fi else ruby -c "$FILE" 1> /dev/null if [[ "$?" -ne 0 ]]; then echo "Syntax Error found in '$FILE'"; fi fi fi # If a file is json, check for syntax errors if [[ "$FILE" =~ .*\.json$ ]]; then if [[ "$fail" -eq 0 || -z "$fail" ]]; then ruby -e "require 'rubygems'; require 'json'; JSON::parse(IO.read('$FILE'))" 1> /dev/null; fail=$? if [[ "$fail" -ne 0 ]]; then echo "Syntax Error found in '$FILE'"; fi else ruby -e "require 'rubygems'; require 'json'; JSON::parse(IO.read('$FILE'))" 1> /dev/null if [[ "$?" -ne 0 ]]; then echo "Syntax Error found in '$FILE'"; fi fi fi # If a file is yaml, check for syntax errors if [[ "$FILE" =~ .*\.yaml$ ]]; then if [[ "$fail" -eq 0 || -z "$fail" ]]; then ruby -e "require 'rubygems'; require 'yaml'; YAML::load(IO.read('$FILE'))" 1> /dev/null; fail=$? if [[ "$fail" -ne 0 ]]; then echo "Syntax Error found in '$FILE'"; fi else ruby -e "require 'rubygems'; require 'yaml'; YAML::load(IO.read('$FILE'))" 1> /dev/null if [[ "$?" -ne 0 ]]; then echo "Syntax Error found in '$FILE'"; fi fi fi fi done echo "Syntax check complete." # Built-in git checks git diff-index --check HEAD -- if [[ "$fail" -ne 0 && -n "$fail" ]]; then echo "Syntax Errors Found. Aborting commit" lod_message exit 1 fi # Check for warnings fail=0 for FILE in `git diff-index --name-only HEAD --` ; do if test -e $FILE; then # If a file is ruby, check for syntax errors if [[ -n `find $FILE -regex ".*\.rb$"` ]]; then warnings=`ruby -c "$FILE" 2>&1 | grep -i warn` if [[ -n "$warnings" ]]; then fail=1; fi fi fi done if [[ "$fail" -ne 0 && -n "$fail" ]]; then echo "Syntax Warnings Found. Aborting commit" lod_message exit 1 fi if [ "$unix_name" != "$mac_unix_name" ]; then for FILE in $whitespace; do echo "Whitespace problem fixed. Please re-add '$FILE' to your commit" done if [[ -n "$whitespace" ]]; then lod_message; exit 1; fi fi # Check that project metadata files exist for FILE in "README.rdoc" "VERSION" ".gitignore" "Rakefile"; do if test ! -e $FILE; then echo "$FILE not present. Aborting commit" exit 1 fi done # Check that username and user emails are filled properly username=`git config --get user.name` useremail=`git config --get user.email` emaildomain=`echo $useremail | grep -o "[^@]*$"` if [[ "$username" == "Put Your Name Here" || "$username" == "" ]]; then echo "Please set your git user.name by running 'git config user.name '" lod_message exit 1 elif [[ "$useremail" == "setyouremail@rightscale.com" || "$useremail" == "" ]] || ! host "$emaildomain" &> /dev/null; then echo "Please set your git user.email by running 'git config user.email '" lod_message exit 1 fi exit 0