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 :)

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

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
  • Daniel: Thanks Tim for coming over! Icant $get that day to me that was like a boost to my skills I was thnki [...]
  • Iyinoluwa Balogun: i think curiousity comes first. those who have left footprints in the sands of time started by quest [...]
  • Kizito S.M.: What I gather is that this G-Buzz is something like a blend between Facebook Updates and Twitter fol [...]
  • concept37: They are trying to out-facebook facebook and out-twitter twitter, Folks who want to do these things [...]
  • ray: Funny u took it from the LBS angle, which makes better sense. But from the social networking perspec [...]

Subscribe to this blog via email

Enter your email address: