-
-
Save odixon/301367ada57fe0782244a7e50695c5e2 to your computer and use it in GitHub Desktop.
PHPLint pre-commit git hook
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 | |
exec('git diff --name-only --diff-filter=ACM --cached', $files); | |
$status = 0; | |
foreach ($files as $file) { | |
if (pathinfo($file, PATHINFO_EXTENSION) != 'php') continue; | |
$file = escapeshellarg($file); | |
$message = array(); | |
exec("git show :$file | php -l 2>&1", $message, $code); | |
if (!$code) continue; | |
fwrite(STDERR, str_replace('in - on', "in $file on", $message[0])."\n"); | |
$status = 1; | |
} | |
die($status); |
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
#!/bin/bash | |
staged="$(git diff --name-only --diff-filter=ACM --cached)" | |
phpfiles="$(grep '\.php$' <<< "$staged")" | |
for file in $phpfiles; do | |
php -l $file > /dev/null || exit 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment