Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the pre-commit hook to clean code

Tags:

git

githooks

Is it good form to scrub development code from my source files during a pre-commit hook?

For example, I have code that is calling xdebug_break() and I want to remove the calls to that function from any files that have it before committing my code to the repository. I would rather not check for the function before calling it because I am the only one that wants that function call there.

like image 598
Craig Gardner Avatar asked Dec 14 '22 00:12

Craig Gardner


1 Answers

The pre-commit hook should only be used for checking the commit, not for modifying it. So, you could use it to check if you have the undesired code in your commit, and abort the commit if you don't, but you should not use it to modify the commit in any way.

It would be possible to use a filter attribute to run a program to "clean" your sources before they are committed; but I would recommend against this. Removing lines of source code can change the behavior of your program. You should not commit any work that you have not tested in the form that it is being committed.

like image 91
Brian Campbell Avatar answered Dec 17 '22 23:12

Brian Campbell