webERP Forum
Git hooks - Printable Version

+- webERP Forum (http://www.weberp.org/forum)
+-- Forum: webERP Discussion (http://www.weberp.org/forum/forumdisplay.php?fid=1)
+--- Forum: Development Tools (http://www.weberp.org/forum/forumdisplay.php?fid=12)
+--- Thread: Git hooks (/showthread.php?tid=8348)



Git hooks - TimSchofield - 06-30-2019

Here is an archive of my git hook scripts as promised in this thread (http://www.weberp.org/forum/showthread.php?tid=8346&pid=15774#pid15774). They need to be placed in the .git directory of your local repository. They work OK in all versions of Linux we have tried them on. I don't possess a Windows box, or a Mac box. They are all either bash scripts, or PCP-CLI scripts (yes I know but it was just easier at the time!) and so the first line in each script should point to the respective binary.

The prepare-commit-msg script was written by my colleague Juergen Mueller and overrides the standard commit message format to what we think is a better layout.
The pre-commit script runs several sub scripts before the code can be committed. These all enforce coding policies on the scripts being committed, or check for syntax errors. If any of these scripts fail, then the commit is aborted with a (hopefully) sensible error message allowing you to track the problem.
The first of these is convert_line_endings_to_unix.sh which uses the dos2unix utility to ensure that line endings are consistently of the unix style rather than the dos style - Git can behave strangely with the dos style line endings.
The second is check_white_space.sh which does a few things to rationalise the use of white space, such as removing trailing white space from lines, it removes unnecessary tabs from css files etc.
The next is check_variable_names.sh which enforces commonly used variables to a certain style. All instances of $sql, $result, $myrow, $pdf are changed to $SQL, $Result, $MyRow, $PDF for consistency with the rest of the code.
Then we have format_code.sh which uses an amended version of PHP beautifier (https://pear.php.net/package/PHP_Beautifier/) to format the code to conform with the old coding guidelines. If anybody is interested I can help with amending PHP beautifier. I think as well paths on my machine are hard coded in these scripts so beware Smile
Finally there is syntax.sh which uses php -l to check the syntax of the scripts being committed.

Please feel free to use some or any of these hooks if they are of interest.

Tim

[attachment=966]


RE: Git hooks - TimSchofield - 07-02-2019

If it is of any interest to anybody I have put them on GitHub https://github.com/timschofield/hooks