Skip to content

Instantly share code, notes, and snippets.

@petitchevalroux
Last active September 5, 2015 09:20
Show Gist options
  • Save petitchevalroux/2659161e7776166c5d41 to your computer and use it in GitHub Desktop.
Save petitchevalroux/2659161e7776166c5d41 to your computer and use it in GitHub Desktop.
pre-commit php hooks
#!/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