Using Git to Manage Todos

A common convention when writing software is to add TODO or FIXME comments directly to the codebase. These comments clearly mark bits of logic that are yet to be implemented or are in need of review.

One problem with this approach is that it’s easy to ignore these comments, and under the human pressures of deadlines and multi-tasking, the comments are forgotten about and are left to linger and rot. The number of TODO comments in the codebase grows over time, gradually becoming more intimidating, more unwieldy, and less useful.

In order to coerce my colleagues (and myself) into taking better care of our heaving pile of TODO comments, I added a post-commit hook that runs grep across the directories we care about.

The output gives me the following bits of information:

The file path

The line number where the TODO was found

The TODO message

This is a good start; at least everyone on the team will now see a list of all TODO items every time they push some commits. The problem now though, is that all of the TODO items are mixed together and it’s difficult to know who is responsible for which item. We could introduce some convention where everyone adds their name to their TODO, but realistically people just wouldn’t adhere to that.

What’s missing from my ideal output is the author of each TODO item. We can use git log to find the author of a commit, and using the -L flag the command will take a range of lines and a file path, both of which we find in our grep output. The approach then, is to iterate over our grep output, pull the file path and line number out of each search match, plug those into git log to find the author, and glue the pieces back together to build the output we need.

I think this approach is probably good enough. Allowing a list of TODO items to grow like weeds is a human problem that can’t exactly be solved elegantly with technology alone, but at least the problem is now far more visible to all of the developers on my team so they have chance at doing something about it.

A few non-obvious technical considerations: