Skip to content

Instantly share code, notes, and snippets.

@mpatnode
Forked from kkopachev/post-checkout
Last active September 16, 2016 17:26
Show Gist options
  • Save mpatnode/4a5b5d386faad449215481935e6d0987 to your computer and use it in GitHub Desktop.
Save mpatnode/4a5b5d386faad449215481935e6d0987 to your computer and use it in GitHub Desktop.
composer install post-checkout hook
#!/bin/bash
# Put this file at: .git/hooks/post-checkout
# and make it executable
# You can install it system wide too, see http://stackoverflow.com/a/2293578/685587
PREV_COMMIT=$1
POST_COMMIT=$2
GIT_DIR=$(git rev-parse --git-dir)
GIT_DIR_MERGE="$GIT_DIR"/rebase-merge
GIT_DIR_APPLY="$GIT_DIR"/rebase-apply
GIT_MERGE_REBASE=false
[[ (-d "$GIT_DIR_MERGE" && -f "$GIT_DIR_MERGE/interactive") || -d "$GIT_DIR_APPLY" ]] && GIT_MERGE_REBASE=true
NOCOLOR='\e[0m'
REDCOLOR='\e[37;41m'
function composerlock {
echo -e "$REDCOLOR composer.lock has changed: running composer install $NOCOLOR"
if pwd | grep musthave > /dev/null 2>&1; then
WORKDIR=/var/www/musthave
else
WORKDIR=/var/www/drupal.popsugar.com
fi
COMPOSER=
# If you're running git on your Host, you want composer to run within vagrant
if which vagrant > /dev/null 2>&1; then
COMPOSER="vagrant ssh -c \'(cd $WORKDIR; fcomposer install)\'"
fi
if which fcomposer > /dev/null 2>&1; then
COMPOSER="fcomposer install"
fi
if [ -f composer.phar ]; then
COMPOSER="php composer.phar install"
fi
which composer > /dev/null 2>&1
if [ $? ]; then
COMPOSER="composer install"
fi
if [[ $GIT_MERGE_REBASE = false && -n "$COMPOSER" ]]; then
eval $COMPOSER
fi
}
DIFF=$(git diff --shortstat $PREV_COMMIT..$POST_COMMIT composer.lock 2>/dev/null)
if [[ $DIFF != "" ]]; then
composerlock
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment