Created
June 2, 2014 23:49
-
-
Save davehughes/c115a7adbb6bd9f99945 to your computer and use it in GitHub Desktop.
Detect duplicate indices in South migrations between two git commits
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
RETURN_CODE=0 | |
MIGS_PATH="thefundersclub/migrations" | |
# List the IDs of any migrations added since the previous commit | |
NEW_MIGS=$(git log --name-status $GIT_PREVIOUS_COMMIT..$GIT_COMMIT -- $MIGS_PATH | egrep 'A\tthefundersclub/migrations' | cut -f 2 | xargs basename | cut -d_ -f 1) | |
echo "Checking new migrations for duplication: $NEW_MIGS" | |
# List the last N migration IDs | |
EXISTING_MIGS=$(git ls-tree -r $GIT_PREVIOUS_COMMIT | grep $MIGS_PATH | cut -d" " -f 3 | cut -f 2 | xargs basename | cut -d_ -f 1 | sort | tail -n 20) | |
echo "Existing migs: " $EXISTING_MIGS | |
MERGED_MIGS=$(echo $NEW_MIGS $EXISTING_MIGS | tr -s " " "\n" | sort) | |
echo "Merged migs: " $MERGED_MIGS | |
DUPES=$(printf "$MERGED_MIGS" | uniq -d) | |
if [[ $DUPES != "" ]]; then | |
echo "Found duplicate migration(s): $DUPES" | |
RETURN_CODE=1 | |
fi | |
exit $RETURN_CODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment