Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched to faster, simpler bash version
- Loading branch information
Showing
1 changed file
with
14 additions
and
26 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,17 @@ | ||
#!/usr/bin/php | ||
<?php | ||
#!/bin/bash | ||
|
||
$output = array(); | ||
$return = 0; | ||
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return); | ||
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904'; | ||
files_modified=`git diff-index --name-only HEAD` | ||
|
||
exec("git diff-index --cached --name-only {$against}", $output); | ||
# PHP lint files | ||
|
||
$filename_pattern = '/\.php$/'; | ||
$exit_status = 0; | ||
|
||
foreach ($output as $file) { | ||
if (!preg_match($filename_pattern, $file)) { | ||
// don't check files that aren't PHP | ||
continue; | ||
} | ||
|
||
$lint_output = array(); | ||
exec("php -l " . escapeshellarg($file), $lint_output, $return); | ||
if ($return == 0) { | ||
continue; | ||
} | ||
echo implode("\n", $lint_output), "\n"; | ||
$exit_status = 1; | ||
} | ||
|
||
exit($exit_status); | ||
for f in $files_modified; do | ||
if [[ $f == *.php ]]; then | ||
php -l "$f" > /dev/null | ||
if [ $? != 0 ]; then | ||
echo "Code fails PHP lint check." | ||
echo "Aborting commit. Commit again with --no-verify to ignore." | ||
exit 1 | ||
fi | ||
fi | ||
done | ||
exit |