Skip to content

Instantly share code, notes, and snippets.

@yehosef
Last active December 19, 2016 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yehosef/8ffbab1f2dbbef22b757 to your computer and use it in GitHub Desktop.
Save yehosef/8ffbab1f2dbbef22b757 to your computer and use it in GitHub Desktop.
git hook to update composer dependencies only if changed, and to put the current revision in a file
#!/bin/bash
#set -x
githooks/post-checkout-revision.sh
githooks/post-checkout-composer.sh
#!/bin/bash
OLD=`md5 -q composer.lock.old`
NEW=`md5 -q composer.lock`
if [ "$NEW" != "$OLD" ]
then
rm -rf vendor
php composer.phar install
fi
cat composer.lock > composer.lock.old
#!/bin/bash
b=$(git rev-parse --show-toplevel)
output_file=$b/docroot/www/revision.txt
branch=`git rev-parse --abbrev-ref HEAD `
revision=`git rev-parse HEAD`
echo -e "$branch $revision \n" > $output_file
current_date=`date +%A\ %F\ %r`
echo "Checkout at:$current_date" >>$output_file
last_commit_at=`git log -1 HEAD --date=local --decorate --pretty=format:"%cd"`
echo "Last commit at: $last_commit_at " >>$output_file
@yehosef
Copy link
Author

yehosef commented Feb 3, 2015

you should add the composer.lock to the repo and add composer.lock.old to the .gitignore.
When you want to manually do an update, just run composer update and the commit the lock file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment