Last active
September 5, 2015 09:20
-
-
Save petitchevalroux/2659161e7776166c5d41 to your computer and use it in GitHub Desktop.
pre-commit php hooks
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 | |
//Récupération des fichier modifiés par le commit | |
exec('git diff --name-only HEAD | grep -E \'(.php)$\'', $output); | |
$cmds = [ | |
['cmd' => 'php-cs-fixer fix'], | |
['cmd' => 'php -l','return' => 0], | |
]; | |
foreach ($output as $file) { | |
echo "Checking php file $file\n"; | |
foreach ($cmds as $cmd) { | |
exec($cmd['cmd'].' '.escapeshellarg($file), $output, $return); | |
if (isset($cmd['return']) && $return !== $cmd['return']) { | |
exit(1); | |
} | |
} | |
} | |
if (file_exists('Makefile')) { | |
exec('make tests', $output, $return); | |
if ($return !== 0) { | |
echo "Tests [KO]\n"; | |
exit(1); | |
} | |
echo "Tests [OK]\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment