Skip to content

Instantly share code, notes, and snippets.

@Andrew8xx8
Created November 6, 2012 06:32
Show Gist options
  • Select an option

  • Save Andrew8xx8/4023001 to your computer and use it in GitHub Desktop.

Select an option

Save Andrew8xx8/4023001 to your computer and use it in GitHub Desktop.
Git hooks for CS-Cart repo
#!/usr/bin/php
<?php
if (!empty($argv[1])) {
$commit_message = file_get_contents($argv[1]);
if (!preg_match("/\[.\]\s.*?/", $commit_message)) {
echo "\n Cannot commit. \n Wrong commit message format.";
} else {
exit (0);
}
} else {
echo "Cannot commit. Empty commit message.";
}
exit (1);
?>
#!/usr/bin/php
<?php
//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);
echo "Codestyle in some files will be fixed. \n ";
foreach ($output as $line) {
$action = trim($line[0]);
$fileName = trim( substr($line, 1) );
if (preg_match("/\.php$/", $fileName)) {
echo fixSyntax($fileName);
exec ("php -l $fileName", $_output, $return_var);
if ($return_var !== 0) {
echo "\n!!! Sorry you files contain wrong syntax. Check it ad commit again. \n\n";
exit(1);
} else {
exec("git add " . $fileName);
}
}
}
exit(0);
function fixSyntax($fileName)
{
exec("php _tools/codestyle/php-cs-fixer.phar -v fix $fileName ", $output);
return implode("\n", $output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment