- Yair Mark
Today after working on a branch for a while I ran into a weird runtime issue. There was some sort of funky JPA thing going on which was causing an error but the stack trace did not point to anywhere in my code that made sense with the error happening. Basically, there was an issue happening consistently with no obvious reason why.
I first started by trying to Google the issue but to no avail. I then tried to run my project's integration tests and lo and behold one of my tests consistently failed with the same error :)
I have heard of git bisect and know roughly how it works but I have never had to use it. In a nutshell, git bisect lets you point at a known good commit and a known bad commit. You then tell git what script to run, this script needs to return a zero error code to signify success or a non-zero code to signify an error. Git then checks out commits between the good and bad commits, runs this script and finished when it pinpoints the exact commit the issue started happening in.
I did not feel like writing a script and figured that there must be a way to get Intellij to run a given test using Git bisect. A short Google later and I found a plugin that does exactly this: git bisect run.
This plugin adds a little run button next to your run toolbar in Intellij. On clicking it you tell it the good branch/hash and the bad one. You then push run against the current run option (you can probably run this against any IntelliJ run config) and it does its magic. It will tell you the exact commit the issue started cropping up.
One thing that was not too obvious about the plugin was the fact that you can paste git hashes into the boxes for the good and bad commits - initially it seems like it forces you to choose a branch but you can paste a hash instead.
Once you pinpoint the issue you need to look through the commit and see what could have caused the issue. In my case the issue was a DB one, I saw only 2 DB entities that had changed and pinpointed the exact issue. Git bisect can save you hours of manual debugging.