Sha256: b97306963f1a0a320fb737aba9eb5ff4e39d58412e63c4355c2c2e1a84f53a3f

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

#!/bin/bash

whitespace=""
for FILE in `git diff-index --name-only HEAD --` ; do
  if test -e $FILE; then
    if [[ -n `grep "\\s\\s*$" $FILE` ]]; then whitespace="$whitespace $FILE"; fi
    # Remove trailing whitespace
    sed -i "s/\\s\\s*$//g" $FILE
    # Remove tabs
    sed -i "s/\t/  /g" $FILE
    # If a file is ruby, check for syntax errors
    if [[ -n `find $FILE -regex ".*\.rb$"` ]]; then
      if [[ "$fail" -eq 0 || -z "$fail" ]]; then
        `ruby -c $FILE 1> /dev/null`; fail=$?
      else
        `ruby -c $FILE 1> /dev/null`
      fi
    fi
  fi
done

# Built-in git checks
git diff-index --check HEAD --

if [[ "$fail" -ne 0 && -n "$fail" ]]; then
  echo "Syntax Errors Found. Aborting commit"
  exit 1
fi

for FILE in $whitespace; do
  echo "Whitespace problem fixed. Please re-add '$FILE' to your commit"
done
if [[ -n "$whitespace" ]]; then exit 1; fi

# Check that project metadata files exist
for FILE in "Rakefile" "README.rdoc" "VERSION" ".gitignore" "rest_connection.gemspec"; 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" == "" ]]; then
  echo "Please set your git user.name by running 'git config user.name <your github username>'"
  exit 1
elif [[ "$useremail" == "" ]] || ! host "$emaildomain" &> /dev/null; then
  echo "Please set your git user.email by running 'git config user.email <your github email>'"
  exit 1
fi

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rest_connection-0.1.1 git_hooks/pre-commit
rest_connection-0.1.0 git_hooks/pre-commit