Git hooks for PHP projects with Crook

Felipe Lopes
Oct 23, 2018 · 5 min read
Photo by Sara Cardoso on Unsplash

What I was looking for?

I wanted the most simple thing: the event happens, then trigger some code wrote by me or by someone else. No matter the language, if I want to plug a pre-commit hook to a Ruby script, that’s OK. If I want to run a Bash script, a binary in Golang, whatever. For me, the tool must just take the event and trigger the hooked action. That’s it. I didn’t find it. And what do we do when we cannot find the right tool? We create one and make it Open Source. : )

First, the requirements

I need something to manage client-side Git hooks. The tool should allow me to run whatever I want when some client-side hook event is triggered, no matter the language. It must be simple, straightforward, easy to install, easy to use, must be a package available on Packagist, have few dependencies, and be written in PHP.

Here comes Crook

Crook is (at least for me) the simplest way to manage Git hooks in your PHP projects. Is my attempt on helping create a nice tool for the job. In the following sections, I’m gonna explain in a little more detail about how everything works and how you can use it to integrate actions and hooks on your projects. I published it on Packagist here and you can find the source code on my GitHub page here.

How does it work?

First, you run

The mechanism

Git hooks are based on actions/files you create inside .git/hooks. So, if you go to your project and list this directory you will find some sample files to help you create your own hooks.

The project

I had a nice time creating this and I hope it can be helpful to your project. You can find more about Crook on its Github page. My last commit was a few months ago, but it seems to be really stable and has some tests. I know of a company using it to manage hooks for a PHP team and I got a few good feedbacks. I would be flattered if someone could use it, find issues, report them, and maybe contribute. Any criticism or questions are welcome.

This story is published in The Startup, Medium’s largest entrepreneurship publication followed by + 382,862 people.

Subscribe to receive our top stories here.

The Startup

Medium's largest active publication, followed by +469K people. Follow to join our community.

Felipe Lopes

Written by

Software engineer

The Startup

Medium's largest active publication, followed by +469K people. Follow to join our community.