-
-
Save alonisser/6270653 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/sh | |
#Inspired by https://gist.github.com/jbergantine/3870080 | |
#Since every `git pull` is actually a merge. We can use it to automaticly run basic Django tasks after pulling from the upstream master branch (or any other) | |
#Notice: This won't run at git fetch. since fetch doesn't merge anything | |
#Installation: | |
# copy this script with the name:`post-merge.sh` to your project root folder | |
# symlink it to the ./git/hooks/post-merge: `ln post-merge.sh .git/hooks/post-merge | |
#You should have bash (windows users, means cygwin/mingw anything that works for you | |
#Based on the instructions here: https://oknesset-devel.readthedocs.org/en/latest/workflow.html#before-coding | |
if [ $(python -c "import sys; print(sys.prefix == sys.real_prefix)" | grep False -c) -eq 0 ] | |
then | |
echo "you aren't pulling in a virtualenv, no automatic mergehandling for you!" | |
exit 0 | |
fi | |
if [ $(git diff HEAD@{1} HEAD --name-only | grep 'requirements.txt' -c) -ne 0 ] | |
then | |
#Notice you should run this script inside a working virtualenv | |
pip install -r requirements.txt | |
fi | |
#python manage.py syncdb | |
if [ $(git diff HEAD@{1} HEAD --name-only | grep 'migrations' -c) -ne 0 ] | |
then | |
python manage.py migrate | |
fi | |
python manage.py test | |
When inside a virtualenv, the VIRTUAL_ENV
env variable is set.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the grep exit code directly in the condition instead of doing a numerical check:
e.g. replace line 17 by