Skip to content

Instantly share code, notes, and snippets.

@alonisser
Forked from bergantine/gist:3870080
Last active December 21, 2015 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alonisser/6270653 to your computer and use it in GitHub Desktop.
Save alonisser/6270653 to your computer and use it in GitHub Desktop.
#!/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
@alonisser
Copy link
Author

I Still need to to check if python manage.py test would work since test is a bash keyword

@elazarg
Copy link

elazarg commented Aug 31, 2013

test is not a bash keyword since bash has none. It is a bash command (only within an appropriate context) and an executable filename. Here, test is a command-line argument, so it is legal just like any other string.

@yoniLavi
Copy link

yoniLavi commented Sep 1, 2013

You can use the grep exit code directly in the condition instead of doing a numerical check:
e.g. replace line 17 by

if git diff HEAD@{1} HEAD --name-only | grep 'requirements.txt' -q

@nonZero
Copy link

nonZero commented May 1, 2014

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