Skip to content

Instantly share code, notes, and snippets.

@schmunk42
Created August 17, 2014 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmunk42/a4bad83dab5ba542cb1f to your computer and use it in GitHub Desktop.
Save schmunk42/a4bad83dab5ba542cb1f to your computer and use it in GitHub Desktop.
git hook to check changes in composer lock file with PHP
#!/usr/bin/php
<?php
/**
* Hook to tell you, when you have to trigger composer install
*
* Installation:
*
* cd .git/hooks/
* ln -s ../../git-hooks/post-merge .
*/
$rootPath = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR;
$lockFile = $rootPath.'composer.lock';
$hashFile = $rootPath.'composer.lock.hash';
function msg() {
echo "\n================\n";
echo "Important Notice\n";
echo "================\n\n";
echo "Your composer.lock file has been updated, please run \n\n php composer.phar install\n\nto ensure vendor folder integrity!\n";
echo "\n";
}
$currentHash = md5_file($lockFile);
if (is_file($hashFile)) {
$lastHash = file_get_contents($hashFile);
echo "\nVerifying composer Installation";
echo "\nLast Install Hash : ".$lastHash;
echo "\nCurrent Install Hash: ".$currentHash;
if ($lastHash != $currentHash) {
msg();
}
} else {
msg();
}
echo "\n";
file_put_contents($hashFile,$currentHash);
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment