Created
January 21, 2016 01:30
-
-
Save AramZS/f2a2a9ce3c5a478bd3a0 to your computer and use it in GitHub Desktop.
Githook to assure file permissions (must be +x ed)
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 | |
echo "Start a git filecheck \n"; | |
$output = array(); | |
$return = 0; | |
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return); | |
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904'; | |
exec("git diff-index --cached --name-only {$against}", $output); | |
$filename_pattern = '/\.php$/'; | |
$exit_status = 0; | |
#var_dump($output); | |
array_shift($output); | |
#var_dump($output); die(1); | |
foreach ($output as $file) { | |
if ("0775" != substr(sprintf('%o', fileperms($file)), -4)){ | |
echo $file." is not set to permission 775. Setting now, redo commit. \n"; | |
chmod($file, 0775); | |
$exit_status = 1; | |
} | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment