Skip to content

Instantly share code, notes, and snippets.

@mikeclarke
Created May 9, 2012 06:29
Show Gist options
  • Save mikeclarke/2642393 to your computer and use it in GitHub Desktop.
Save mikeclarke/2642393 to your computer and use it in GitHub Desktop.
#!/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
@NorthIsUp
Copy link

What is the result of line 17?

@mikeclarke
Copy link
Author

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