Using git hooks to check syntax errors

In: Programming|Web Development

25 Sep 2009

Git is currently my favorite source code versioning tool and while I used Subversion, I knew about something called hooks that I never used.

Essentially, hooks allow you to execute custom scripts when you perform certain actions on your repository like committing files, pulling updates and so on. This is a very useful as you can write hook scripts to (say for example) automatically ftp a file to your web server when a change has been made.

A whole lot of really cool hook scripts have been written and if you use any code versioning tools, you should check out the ones that have been written for the tool you use.

In particular, I find that sometimes developers could check in code that has syntactic bugs. This happens in environments where there are no strict code testing rules. It can be really annoying when you or someone else does this and you have to fix that and then commit again… not professional at all. So I came across this post by Travis Swicegood that lists code that does a php lint on your PHP files before committing them to the repository. PHP lint (php -l) basically checks the syntax of your code and either gives an “ok” or prints the offending line.

For one of the projects I’m working on, I had to change line 11 of Travis’ code to read:

$filename_pattern = '/\.(php|engine|theme|install|inc|module|test)$/';

instead of

$filename_pattern = '/\.php$/';

If you’ve done Drupal coding, you’ll quickly recognize that :)

Comment Form

About this blog

Tim Akinbo's Weblog is the personal weblog of Tim Akinbo. Here he discusses issues relating to technology. Special interests include the web, mobile technology and location based services.

Photostream

    Panel Session on Realizing Nigeria's Internet PotentialDelegates during Justin's Keynote PresentationBarCamp Attendees 1main hallmain hall 2main hall 3
  • Budzeg: I remember the days of mobile too... When we were building wapitis like it was going out of fashion. [...]
  • damiet: Tim i think the society has in some way showed us that technology, engineering, etc are male stuff. [...]
  • Tim: @Trae, my memory fails me. You\'re right I did start blogging in 2004 :) Hmm... so many years gone b [...]
  • trae_z: I started blogging late 2008. For one reason or the other, I lost the first two incarnations of m [...]
  • Tim: That would depend on what application is being built but I did read up uniPaaS and it's worth t [...]

Subscribe to this blog via email

Enter your email address: