-
-
Save sunel/6aaa3fe6a8cc4bbdbe89 to your computer and use it in GitHub Desktop.
Revisions
-
phpfunk revised this gist
Jun 4, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,4 +4,5 @@ It will only check files that have one of the extensions listed in the `$extensi Things to note: * You may have to change the `#!/usr/bin/php` to point to your path for PHP * If you don't want to check untracked files, remove the `$untracked` variable. * Place `pre-commit` file in your `.git/hooks` folder and `chmod +x .git/hooks/pre-commit` -
phpfunk revised this gist
Jun 4, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ foreach ($files as $file) { if ($return == 0) { continue; } echo implode("\n", $output) . "\n"; $status = 1; } } -
phpfunk created this gist
Jun 4, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #!/usr/bin/php <?php // Set empty files array $files = array(); // Get untracked files // Get modified files exec('git ls-files --others --exclude-standard', $untracked); exec('git diff --cached --diff-filter=ACMRTUX --name-only', $modified); // Merge em $files = array_merge($untracked, $modified); // Set extensions to check $extensions = array('php', 'tmpl'); // Check their syntax foreach ($files as $file) { $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (in_array($ext, $extensions)) { $output = array(); exec('php -l ' . escapeshellarg($file), $output, $return); if ($return == 0) { continue; } echo implode("\n", $output), "\n"; $status = 1; } } // Set exit status // 0 = good, 1 = fail $status = (!isset($status)) ? 0 : 1; exit($status); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ This is a very easy way to check your PHP syntax before each commit. Git will call the script before it runs your commit. If there are syntax errors found, they won't be committed and they will be reported. It will only check files that have one of the extensions listed in the `$extensions` array. It's a pretty simple script and comes in handy if you are working locally before you push to a remote for testing. Things to note: * You may have to change the `#!/usr/bin/php` to point to your path for PHP * If you don't want to check untracked files, remove the `$untracked` variable.