I’ve been working with some very aggressive TDD that removes code that’s not covered. That’s pretty great.


ptw --onpass "git add .; git commit --no-verify -m 'green'" \
  --afterrun "python delete_uncovered/remove.py" \
  -- tests/integration/ \
  -vv --ff --exitfirst \
  --cov --cov-report xml -s --cov-config=.coveragerc-custom

For the curious, here’s how we’re removing uncovered code.

One problem is all the interim commits are junk and bypass all the precommit hooks. To get address that, I’ve added a Git alias to find the most recent real commit and a fish_shell script to reset everything to that.

git alias

git config --global alias.realcommit \
  'log --max-count=1 --grep=": green" --invert-grep --format=format:"%H"'

Now git realcommit will find the SHA of the most recent commit with a message that is not “: green”, which is what our checkpoint commits do.

fish_shell script

function green --description 'Reset current Git project to most recent non-green commit'
  git realcommit | xargs git reset --soft

Now typing green in fish finds the SHA of the last real commit and does a soft reset to it. This essentially collapses all the checkpoint commits into one staged change. From there, a normal git commit will take you into your normal flow, including precommits, prepare messages, etc.

This is important to keep all your insane TDD stuff in your local repo and not blow up the remote with things that will make people crazy.

Another gap has appeared. When refactoring, what if (hopefully) code becomes redundant? Source code may only be referenced by its implementation and being exercised by the unit tests. That’s nice that it’s covered, but it’s dead code!

Let’s solve that next.