Skip to content

Instantly share code, notes, and snippets.

@tuttle
Last active October 12, 2022 13:48
Show Gist options
  • Save tuttle/626090dda3e30c2bcb057ed0c33742a8 to your computer and use it in GitHub Desktop.
Save tuttle/626090dda3e30c2bcb057ed0c33742a8 to your computer and use it in GitHub Desktop.
Git pre-commit hook to test the developer didn't forget to create database migrations and that all migrations are staged for commit.
#!/bin/sh
#
# Git pre-commit hook to test the developer didn't forget to create database migrations
# and that all migration files are staged for commit.
#
# Note: chmod +x .git/hooks/pre-commit
#
echo "pre-commit: Checking for forgotten/untracked/unstaged migrations..."
if ! ../../bin/manage.py makemigrations --no-input --dry-run --check
then
echo
echo "Breaking commit: Please run makemigrations first."
echo
exit 1
fi
if git --no-optional-locks status --short | grep -q -E '^\?.*/migrations/'
then
echo
echo "Breaking commit: You seem to have untracked/unstaged migration(s):"
echo
git --no-optional-locks status
exit 2
fi
# flake8
#echo "pre-commit: Static code checking via flake8..."
#
#FLAKE_ERRORS=$($VIRTUAL_ENV/bin/flake8 | tee)
#if [[ $FLAKE_ERRORS ]]; then
# echo
# echo "Breaking commit: Flake8 errors"
# echo "$FLAKE_ERRORS"
# exit 1
#fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment