Created
August 17, 2014 23:28
-
-
Save schmunk42/a4bad83dab5ba542cb1f to your computer and use it in GitHub Desktop.
git hook to check changes in composer lock file with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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