Last active
August 24, 2016 09:40
-
-
Save chalasr/3af69909ad83df8b444f438818a70d7e to your computer and use it in GitHub Desktop.
git pre-commit hook that clean each modified file using php-cs-fixer
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 --cached --name-status --diff-filter=ACM', $output); | |
foreach ($output as $file) { | |
$fileName = trim(substr($file, 1) ); | |
if ("php" == pathinfo($fileName, PATHINFO_EXTENSION)) { | |
$lint_output = array(); | |
exec("php -l " . escapeshellarg($fileName), $lint_output, $return); | |
if ($return == 0) { | |
exec("php-cs-fixer fix {$fileName} --config-file=.php_cs; git add {$fileName}"); | |
echo $file.PHP_EOL; | |
} else { | |
echo implode("\n", $lint_output), "\n"; | |
exit(1); | |
} | |
} | |
} | |
echo 'All source-code is clean'.PHP_EOL; | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment