Skip to content

Commit

Permalink
add git_config
Browse files Browse the repository at this point in the history
  • Loading branch information
dlo committed Aug 4, 2015
1 parent b157338 commit e33b891
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
14 changes: 14 additions & 0 deletions git_config/check_js_code_style.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

CHANGED_JS_FILES=`git diff --cached --name-only | grep -E "^static/js/.*.js" | grep -v .min.js`

if [ -n "$CHANGED_JS_FILES" ]; then
echo "Checking Javascript for the following files:"
echo $CHANGED_JS_FILES

if ! jscs $CHANGED_JS_FILES; then
echo "Javascript issues detected; commit aborted."
exit 1
fi
fi

17 changes: 17 additions & 0 deletions git_config/check_pep8_compliance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

CHANGED_PYTHON_FILES=`git diff --cached --name-only | grep py$`

if [ -n "$CHANGED_PYTHON_FILES" ]; then
CHANGED_FILES=`echo $CHANGED_PYTHON_FILES | tr '\n ' ,`

if ! [ -z "echo $CHANGED_FILES | sed -e 's/^[ \t]*//'" ]; then
echo "Checking PEP-8 Compliance for the following files:"
printf "$CHANGED_PYTHON_FILES\n"
if ! pep8 --filename=$CHANGED_FILES; then
echo "PEP-8 errors detected; commit aborted."
exit 1
fi
fi
fi

25 changes: 25 additions & 0 deletions git_config/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Update Filters
git config filter.sass.clean "sed '/^@media -sass-debug-info/ d'"
git config filter.sass.smudge cat

git config filter.css.clean "css-beautify --end_with_newline --file -"
git config filter.css.smudge cat

git config filter.js.clean "js-beautify --space-after-anon-function --brace-style=end-expand --preserve-newlines --end_with_newline --file -"
git config filter.js.smudge cat

git config filter.noop.clean cat
git config filter.noop.smudge cat

git config filter.xml.clean "xmllint --format -"
git config filter.xml.smudge cat

# Install hooks
cp git_config/hooks/post-checkout .git/hooks
cp git_config/hooks/pre-commit .git/hooks

if [ -f git_config/hooks/post-checkout-user ]; then
cat git_config/hooks/post-checkout-user >> .git/hooks/post-checkout
fi
52 changes: 52 additions & 0 deletions git_config/hooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

if [ -f git_config/configure.sh ]; then
sh git_config/configure.sh
fi

echo "Deleting *.pyc files"
find app -name "*.pyc" -type f | xargs rm

MIGRATION_CHANGES=`git diff --name-status $1..$2 app/migrations/`
if ! [ -z "$MIGRATION_CHANGES" ]; then
echo "The database schema has changed since the previous checkout. You may need to migrate the database to avoid data consistency issues."
echo ""
printf "$MIGRATION_CHANGES\n"
echo ""
fi

# Check if the requirements file has been updated.
REQUIREMENTS_UPDATE=`git diff --name-only $1..$2 requirements.txt`
if ! [ -z "$REQUIREMENTS_UPDATE" ]; then
echo "Requirements have changed since the previous checkout."
echo ""
pip install -qr requirements.txt
fi

# Check if NPM modules have been updated.
JS_UPDATE=`git diff --name-only $1..$2 package.json`
if ! [ -z "$JS_UPDATE" ]; then
echo "NPM modules have changed since the previous checkout."
echo ""
npm install
fi

# Check if gems have been updated.
GEM_UPDATE=`git diff --name-only $1..$2 Gemfile`
if ! [ -z "$GEM_UPDATE" ]; then
echo "Gems have changed since the previous checkout."
echo ""
bundle install
fi

if ! hash js-beautify; then
echo "Installing js-beautify."
echo ""
npm install js-beautify -g
fi

if ! hash jscs; then
echo "Installing jscs."
echo ""
npm install jscs -g
fi
9 changes: 9 additions & 0 deletions git_config/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if [ -f git_config/configure.sh ]; then
sh git_config/configure.sh
else
exit 1
fi

git_config/check_pep8_compliance.sh

0 comments on commit e33b891

Please sign in to comment.