Nothing more embarassing than committing awesome code with a parse error. Quick
php -lwill take care of that. But if your repository has files under many directories and you've made changes to many files, it can be a pain to php -l all of them as you can only pass one file to "php -l" at a time.
Here's a quick shortcut:
svn stat | grep 'php' | awk '{print "php -l " $2}' | sh
"svn stat" will list all files that have been changed. The grep will filter the result and only show PHP files. The awk command takes the 2nd column of the output and does "php -l" on every file in that column.
Granted, this is convenient but painful to type and error prone. Solution: save it in a file svnlint.sh, then add an alias:
alias svnlint='sh ~/svnlint.sh'
At this point, before every:
svn commitdo:
svnlint
Your PHP files will be free of syntax errors (so you can focus on those "real" bugs...)
Comments (5)
If you wanted to be mean you could setup a pre-commit handler to run something like what you've specified, and reject commits that don't compile!
Of course, things might not work out 100%. I've not tried it!
Posted by Dave | May 15, 2007 1:55 PM
Posted on May 15, 2007 13:55
Some people are tying CodeSniffer into their commits too: http://blogs.lib.ncsu.edu/page/web?entry=codesniffer_pear_package
I've integrated it into my "build" process in Eclipse and will add it to my Phing script shortly.
Posted by Keith Casey | July 9, 2007 7:47 AM
Posted on July 9, 2007 07:47
I put the following in ~/bin/svnlint (don't forget to chmod +x it):
#!/bin/sh
svn stat | egrep '(php)|(phtml)' | awk '{print "php -l " $2}' | sh
You can keep going adding extensions to the regex, if you like...
Posted by Kevin Cox | July 17, 2007 6:45 PM
Posted on July 17, 2007 18:45
Fantastic. I knew I needed to use awk somehow, but couldn't get it right. Thanks.
Posted by Braden | September 7, 2007 6:56 PM
Posted on September 7, 2007 18:56
And to continue on Kevin's path, '\.(php)|(phtml)$' seems sensible.
Posted by Braden | September 7, 2007 7:00 PM
Posted on September 7, 2007 19:00