Graham Christensen and I have been working together on a project for a little while, it’s using the Symfony Framework . Graham explains the problem really well with a good solution to it. I’d like to expand on the subject a little bit.
- Even though we are writing PHP, command line scripts should use exit properly. This little hack of having to grep the log file, is just plain silly. We’re going to look into pushing a patch into the Symfony codebase, so the tasks give the proper error codes.
- This doesn’t do a php lint check or a code sniffer check yet, that’s on the way
- This hook needs to be added to each developer’s working copy manually, and the file needs to be made executable. To avoid emailing things back and forth, we’ve added a directory called ‘opt/githooks’, where the pre-commit file exists, on a fresh clone, we require developers to copy the file and make chmod +x it.
Installing a pre-commit hook in Git
This is a dead simple process, but just in case. Copy the code as shown on Graham’s Blog Post
and paste into a file called pre-commit.
cp pre-commit $WC/.git/hooks/ chmod +x $WC/.git/hooks
I’m curious to find out what other Symfony developers are doing as far as pre-commit hooks are concerned, how do you handle pre-commit hooks for entire teams?
All developers on our team have an account on the development server which hosts their separate repository and virtual hosts. That way we can symlink the git hooks to a centrally maintained set of hooks. Of course, this is not an easy option for most typical (i.e. decentralised) Git projects.
All developers on our team have an account on the development server which hosts their separate repository and virtual hosts. That way we can symlink the git hooks to a centrally maintained set of hooks. Of course, this is not an easy option for most typical (i.e. decentralised) Git projects.