Skip to content

Instantly share code, notes, and snippets.

@Vrtak-CZ
Last active December 20, 2015 16:39
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 Vrtak-CZ/6163232 to your computer and use it in GitHub Desktop.
Save Vrtak-CZ/6163232 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
/**
* .git/hooks/pre-commit
*
* This pre-commit hooks will check for PHP error (lint).
*
* @author Mardix http://github.com/mardix
* @author Patrik Votoček http://patrik.votocek.cz
* @since Sept 4 2012
*/
/**
* collect all files which have been added, copied or
* modified and store them in an array called output
*/
exec('git diff --cached --name-status --diff-filter=ACM', $output);
foreach ($output as $file) {
$fileName = trim(substr($file, 1) );
/**
* Only PHP file
*/
if (pathinfo($fileName,PATHINFO_EXTENSION) == "php") {
/**
* Check for error
*/
$lint_output = array();
exec("php -l " . escapeshellarg($fileName), $lint_output, $return);
if ($return !== 0) {
echo implode("\n", $lint_output), "\n";
exit(1);
}
}
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment