-
-
Save vadakattu/c063a8505c1f469be873b316a21d8871 to your computer and use it in GitHub Desktop.
Python pre-commit hook feature to check if python package requirements have changed. Useful for maintaining consistency across virtualenvs. Can be skipped using git commit --no-verify
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 | |
# To version control your hook, save this script inside your repository e.g. .githooks/ | |
# Then run 'git config core.hooksPath .githooks' to point your local repository to it | |
# Check if the python package requirements match the existing requirements | |
pip freeze | diff requirements.txt - | |
if [ $? -ne 0 ] | |
then | |
echo "The requirements have changed!" | |
echo "Update the requirements file and commit it" | |
exit 1 | |
fi | |
# Check that the updated requirements file has been staged | |
CHANGED=`git diff --stat -- requirements.txt | wc -l` | |
if [ $CHANGED -ne 0 ]; | |
then | |
echo "The requirements have changed!" | |
echo "Stage the new requirements file" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment