This feature of git is too cool not to blog about: git bisect, and more specifically, git bisect run.

“git bisect” is a tool that facilitates a binary search of changes to your git repository to help find where a bug was introduced. You can walk through the process manually using “git bisect {good,bad,skip}“, or if you can write a script that automates checking for the bug, you can use “git bisect run scriptname” to have git do all the work for you.

The script should return 0 if the bug does not exist, and some other number (except 125) if the bug does exist.

In my case, Cappuccino’s “steam” build tool was failing, so I wrote a simple script that would test it by trying to run “steam” on Foundation:

#!/bin/sh



# install a known working copy of the build tools

pushd ../tmp/Tools

sudo sh install -tools

popd ../tmp/Tools-tools # build whatever version of Cappuccino git bisect has checked out for us

rm -rf $STEAM_BUILD

ant release # install the freshly built tools

pushd $STEAM_BUILD/Cappuccino/Tools

sudo sh install-tools

popd # run steam on Foundation to see if the built tools work

rm -rf $STEAM_BUILD

pushd Foundation

steam

RETURN=$?

popd # return the recorded return value

exit $RETURN

I provided “git bisect start” with a known bad commit and a known good commit, then ran “git bisect run”:

git bisect start c1e882ace1dd29aea98d9247db304fe5d5077df7 d6c0f8802a2fd3a07e14418de7744ae04ae4499e git bisect run ../test.sh

Sure enough, a few minutes later “git bisect” reported exactly which commit caused the problem: