Created
September 13, 2018 09:30
-
-
Save anapaulagomes/19efd82d2fd5df61abea961cfc4faafa to your computer and use it in GitHub Desktop.
git-pre-commit-hook-django-migrations for bash
This file contains hidden or 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
#!/usr/bin/env bash | |
previous_module='' | |
previous_filepath='' | |
previous_prefix='' | |
status_code="0" | |
for filepath in $(git ls-files -- $(find . -type f -regex '.*\migrations.*\.py$')); do | |
module=${filepath%%/*} | |
if [ "$previous_module" != "$module" ]; then | |
previous_module="$module" | |
fi | |
file=${filepath##*/} | |
prefix=${file%%_*} | |
if [ "$previous_module" == "$module" ]; then | |
if [ "$previous_prefix" == "$prefix" ]; then | |
echo "" | |
echo "Possible duplication:" | |
echo " $previous_filepath" | |
echo " $filepath" | |
status_code="1" | |
fi | |
fi | |
previous_prefix="$prefix" | |
previous_filepath="$filepath" | |
done | |
if [ "$status_code" -ne "0" ]; then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment