Skip to content

Instantly share code, notes, and snippets.

@ithinkihaveacat
Last active December 18, 2015 17:49
Show Gist options
  • Select an option

  • Save ithinkihaveacat/5821313 to your computer and use it in GitHub Desktop.

Select an option

Save ithinkihaveacat/5821313 to your computer and use it in GitHub Desktop.
#!/bin/bash
# NOTE: This (sadly) doesn't work in all situations. See
# https://github.com/composer/composer/pull/1083
# for discussion of some alternatives.
# Checks whether composer.json has changed after checkout, in which
# case you probably need to run 'composer install'.
#
# INSTALLATION
#
# Copy into .git/hooks/post-checkout (and make sure it's executable)
[ ! -f composer.json ] && exit
[ ! -f composer.phar ] && curl -s http://getcomposer.org/installer | php >/dev/null
# -e is supposed to inhibit all output but it doesn't...
( git cat-file -e "$1:composer.lock" >/dev/null 2>&1 ) && ( git cat-file -e "$2:composer.lock" >/dev/null 2>&1 ) && ( git diff --quiet "$1:composer.lock" "$2:composer.lock" ) && exit
if [ "$GIT_COMPOSER_STALE" == "warn" ]; then
echo "composer: composer.lock changed on checkout; consider running 'php composer.phar install'"
else
exec php composer.phar install
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment