Skip to content

Instantly share code, notes, and snippets.

@juliangut
Created August 1, 2017 09:52
Show Gist options
  • Save juliangut/812b36a40d9ffcec02365ab46851ce70 to your computer and use it in GitHub Desktop.
Save juliangut/812b36a40d9ffcec02365ab46851ce70 to your computer and use it in GitHub Desktop.
git post checkout hook for changes detection
#!/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