Skip to content

Instantly share code, notes, and snippets.

@drozdowsky
Last active December 4, 2019 10:11
Show Gist options
  • Save drozdowsky/0c229f3506867852cadbab457f302383 to your computer and use it in GitHub Desktop.
Save drozdowsky/0c229f3506867852cadbab457f302383 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Check if there is a migration conflict in django apps.
# no need for python/django
# drozdowsky & oliwa
#
NEW_MIGRATIONS=$(git diff --name-only origin/master | grep -o ".*/migrations/[0-9]*")
MASTER_MIGRATIONS=$(git ls-tree -r --name-only origin/master | grep ".*/migrations/.*.py")
CURRENT_BRANCH_MIGRATIONS=$(git ls-tree -r --name-only HEAD | grep ".*/migrations/.*.py")
if [ "$MASTER_MIGRATIONS" = "$CURRENT_BRANCH_MIGRATIONS" ]
then
exit 0
else
OLD_IFS="$IFS"
IFS=$'\n'
for i in $NEW_MIGRATIONS; do
MIGRATION_PATH=$(dirname "$i")
MIGRATION=$(echo "$MASTER_MIGRATIONS" | grep "$i")
if [ -n "$MIGRATION" ]; then
MIGRATION_NUMBER=$(echo "$i" | grep -o "[1-9][0-9]*$")
MERGE_NUMBER=$((MIGRATION_NUMBER+1))
while [ "${#MERGE_NUMBER}" -lt 4 ]; do
MERGE_NUMBER="0$MERGE_NUMBER"
done
echo "$CURRENT_BRANCH_MIGRATIONS" | grep -q "$MIGRATION_PATH/${MERGE_NUMBER}_merge">/dev/null
if [ $? -eq 0 ]; then
continue
fi
echo "$i - migration with this number already exist at master branch."
exit 1
else
exit 0
fi
done
IFS="$OLD_IFS"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment