Created
May 9, 2012 06:29
-
-
Save mikeclarke/2642393 to your computer and use it in GitHub Desktop.
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/bash | |
# | |
# A git hook for automatically running commands | |
# based on the name of files modified in the | |
# previous changeset | |
# | |
# To install as a post-merge hook (on `git pull`): | |
# $ cp hook.sh .git/hooks/post-merge && chmod 755 $_ | |
# | |
# To install as a post-checkout hook (changing branches): | |
# $ cp hook.sh .git/hooks/post-checkout && chmod 755 $_ | |
# | |
KEYWORDS=( 'requirements' 'paver' ) | |
# Check if we're in a virtualenv | |
python -c "import sys; sys.real_prefix" &> /dev/null | |
# Check if keywords in changed files list | |
if [ $? -eq 0 ]; then | |
for MATCH in "$KEYWORDS" | |
do | |
git diff --name-only HEAD@{1} HEAD | grep -q $MATCH | |
if [ $? -eq 0 ]; then | |
paver update | |
exit | |
fi | |
done | |
fi |
sys.real_prefix is only set inside virtualenvs, an exception looking up a non-existent attribute causes a non-zero exit code (and skips the paver command).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the result of line 17?