Bug hunting
with Git bisect

By Alessandro Lai / @AlessandroLai

Nomad PHP Lightining talk - 18 august 2016

Who am I

How binary search is used

With git bisect:

  • The list is the commit history of one branch
  • The order is time
  • Who decides if we are before or after?
  • HOW???
    • With a manual inspection
    • Refreshing a page
    • Using an automatic test!

My use case: Paraunit


The landscape

I use Paraunit in 2 different projects:

  1. One (big) project,
    based onto Symfony 2.8
  2. One (smaller, newer) project,
    based onto Symfony 3.0

Note: the 2.8 version in the bridge between 2.7 and 3.0,
so they receive the same patches

Here comes the bug!

A few months ago,
I was upgrading to the latest available patch...

2.8.3 2.8.4
3.0.3 3.0.4

  • Functional tests failing randomly
  • I wasn't able to reproduce the issue outside my projects
  • I had to debug it from my vendor folder


$ rm -rf vendor/symfony/symfony

$ composer install --prefer-source

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
  - Installing symfony/symfony (v2.8.9)
    Cloning df02dd5d3f7decb3a05c6d0f31054b4263625dcb


$ cd vendor/symfony/symfony
$ git status
HEAD detached at v2.8.9
nothing to commit, working directory clean

Let's start!

$ git bisect start

$ git checkout v2.8.3
Previous HEAD position was df02dd5... Merge pull request #19487 from fabpot/release-2.8.9
HEAD is now at 7a9a5fc... Merge pull request #17952 from fabpot/release-2.8.3
$ git bisect good

$ git checkout v2.8.4
Previous HEAD position was 7a9a5fc... Merge pull request #17952 from fabpot/release-2.8.3
HEAD is now at 9e14f9f... Merge branch '2.7' into 2.8
$ git bisect bad
Bisecting: 154 revisions left to test after this (roughly 7 steps)
[ff93c1a0266d766c0643c6fd862b00fe0e4dd54e] bug #18087 [WebProfiler] Sidebar button padding (rvanlaak)

Moving forward

$ git bisect bad
Bisecting: 37 revisions left to test after this (roughly 5 steps)
[4fece2877337b182927331a728a3bed90f9fb394] bug #18175 [Translation] Add support for fuzzy tags in PoFileLoader (nud)

Roughly 5 steps later...

$ git bisect bad
b2293515a491db91e8ee85178558461374161a77 is the first bad commit
commit b2293515a491db91e8ee85178558461374161a77
Author: Nicolas Grekas <nicolas.grekas@gmail.com>
Date:   Wed Mar 16 16:22:42 2016 +0100

    [PhpUnitBridge] Revert 7f62133939b1172e1c9924d211e1d315230b3be8

:040000 040000 4cf2abdee62e5708f91a8025e81a1fad5a91e154 182f7ddb10abb302c077a8a248cf285fd1a43c2e M	src

Using alternate terms

  • If you don't like good and bad,
    you can use old and new!
  • You shouldn't mix different pairs of terms;
    use git bisect terms to get a reminder
  • You can also define your own terms!
    $ git bisect start --term-old fast --term-new slow

Manual checkout

$ git checkout baf35cf3c0e09a2de186e135cfcc001956a923f0
$ git bisect bad
Bisecting: 2 revisions left to test after this (roughly 1 step)
[478c49a8aae66c4701ccd8fcba979cb17c038327] update CONTRIBUTORS for 2.3.38


$ git bisect skip
Bisecting: 37 revisions left to test after this (roughly 5 steps)
[2a2aefa4b7c3ee573f0d11b36ce4411787b95180] minor #18119 [Hack Day] Issue for newcomers (2). Replace perfom by perform (JuanLuisGarciaBorrego)

If you skip too much...

$ git bisect skip
There are only 'skip'ped commits left to test.
The first bad commit could be any of:
We cannot bisect more!

...and that's all, folks!

Thank you for your attention!

Please rate my talk on Joind.in!