Skip to content

Instantly share code, notes, and snippets.

@eddyxu
Created August 25, 2012 02:32
Show Gist options
  • Save eddyxu/3459054 to your computer and use it in GitHub Desktop.
Save eddyxu/3459054 to your computer and use it in GitHub Desktop.
Git pre-commit script
#!/bin/sh
#
# Git Precommit Script for Research project.
# Lei Xu <eddyxu@gmail.com>
# Enforce C++ Style Checking (Google C++ Style).
# Note: you must have cpplint.py installed in your $PATH
CPPFILES=`git diff --cached --name-only | grep -E '^.+\.(h|hpp|cpp|cc)$'`
if [ ! -z "$CPPFILES" ]; then
echo "$CPPFILES" | xargs -n 128 cpplint.py
[ $? -gt 0 ] && exit 1
fi
# Enforce Python Style Checking (PEP8)
# http://www.python.org/dev/peps/pep-0008/
# Note: must have pep8 installed in $PATH.
PYFILES=`git diff --cached --name-only | grep -E '^.+\.py$'`
if [ ! -z "$PYFILES" ]; then
# TODO: add pylint check someday?
echo "$PYFILES" | xargs -n 128 pep8
[ $? -gt 0 ] && exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment