red, green, refactor … commit

As time passes I find myself getting more and more nervous about the amount of time between passing tests, and between commits to the source code repository. So when Neil asked me today where I put the “commit” step in my TDD practice, I said:

red
green
   commit
refactor
   commit

That extra “commit” at the green bar captures the safe state, in case I get distracted by the kids or forget to take my medication. It also shares that working code with the rest of the team, which in turn makes sure I get feedback on whether it builds. And that also makes sure those tests get run more frequently and outside of my environment sooner.

Recently I’ve been learning to use Git (which I like a lot, although some of the differences from Subversion stil baffle me a little). Anyroadup, with Git I can get even more safety from the process:

red
   commit
green
   commit
   push
refactor
   commit
   push

The extra “commit” at the red bar is local to my repository. It means I can “stop on a red bar”, as used to be recommended in the early days of TDD, and yet still have all my code checked in.

I wonder whether I’m becoming more paranoid as Old Age now has me in its grip…

Advertisements

3 thoughts on “red, green, refactor … commit

  1. I follow a similar pattern to yours, except after green I use git commit –amend. This appends to the last commit rather than creating a new one. The reason I do this is that I prefer code in my remote repository to always be in a passing state. In the case of merging, rollback or rebasing (which I do often when I sync my local repo to a remote one that others are working on), it’s nicer not to have to deal with any red commits — once I rebase, fix any conflicts and make sure all the tests pass I know it’s safe to push.

  2. High five. I do exactly the same now I work with git.

    The nice think about commiting on red is that you can git pull –rebase on that code (if you dare) and make sure the work you do to get to green includes working with any of your team’s changes.

    I like the git commit –ammend trick too, and will be using that – thanks Dan.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s