Created
August 1, 2017 09:52
-
-
Save juliangut/812b36a40d9ffcec02365ab46851ce70 to your computer and use it in GitHub Desktop.
git post checkout hook for changes detection
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/bash | |
# https://gist.github.com/gurglet/1780139 | |
# Git post checkout hook. | |
# Reminds you of South migration changes when switching branches. | |
# Can be useful when you are testing out a branch from | |
# someone else that requires migrations. | |
# Put the file in .git/hooks/post-checkout | |
PREVIOUS_HEAD=$1 | |
NEW_HEAD=$2 | |
BRANCH_SWITCH=$3 | |
if [ $PREVIOUS_HEAD != $NEW_HEAD ]; then | |
# Start from the repository root. | |
cd ./$(git rev-parse --show-cdup) | |
# Check if any migrations have changed. | |
CHANGED=`git diff $PREVIOUS_HEAD $NEW_HEAD --name-status | grep "^M.*composer.lock"` | |
if [ $? -eq "0" ]; then | |
echo -e "\033[7;31m Beware. composer.lock is changed. Update by running:" | |
echo -e "\033[7;31m composer install" | |
fi | |
# Check if submodules have been changed | |
MODULES=`git diff $PREVIOUS_HEAD $NEW_HEAD --name-status | grep "\.gitmodules$"` | |
if [ $? -eq "0" ]; then | |
echo -e "\033[7;31m The submodules in this project has changed. Update submodules by running:" | |
echo -e "\033[7;31m git submodule update --init" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment