Ruby


2
Dec 10

Git bisect is the best thing ever

I’ve raved about this command to coworkers before, but this morning after a bundle install with edge Rails our multi-database migrations broke, and I needed to figure out why. This had happened sometime between November 15 and December 2… on a less active codebase that might not be a big deal, but there were 204 commits to Rails in that time.

Enter git bisect!

$ cd rails/
local:rails matt$ git bisect start
local:rails matt$ git bisect bad
local:rails matt$ git bisect good 8124b2bc24b8312ee4d1ce2f133bf6e2dd87ad49
Bisecting: 204 revisions left to test after this (roughly 8 steps)
[51007f1dbafe029ed85b2a296736a00e6b24ec58] Previous version inaccurately suggested that
local:rails matt$ git bisect bad
Bisecting: 101 revisions left to test after this (roughly 7 steps)
[77440ec51ad28a7e63651f0976053584a7f58768] fixing assertions so error messages will be more helpful
local:rails matt$ git bisect good
Bisecting: 50 revisions left to test after this (roughly 6 steps)
[96b50a039276b4391ddf07b0a74850ce7bad6863] IrreversibleMigration is raised if we cannot invert the command
local:rails matt$ git bisect bad
Bisecting: 25 revisions left to test after this (roughly 5 steps)
[56c5820458fd3981161393c285cce67fdf35e60b] use shorter form for sql literals
local:rails matt$ git bisect bad
Bisecting: 12 revisions left to test after this (roughly 4 steps)
[f14c2bf58204f488cbe589e077a124865ea595f5] Pass the view object as parameter to the handler. Useful if you need to access the lookup context or other information when compiling the template.
local:rails matt$ git bisect bad
Bisecting: 5 revisions left to test after this (roughly 3 steps)
[974ff0dd43826aa375417852356ceede1bd24cf2] singleton method added is no longer needed
local:rails matt$ git bisect bad
Bisecting: 2 revisions left to test after this (roughly 2 steps)
[fe2f168d40385a0412f41c1a2a44a5536cada8df] fix warning during test execution
local:rails matt$ git bisect good
Bisecting: 0 revisions left to test after this (roughly 1 step)
[0bea9fd6be1c82154d7b2d4adbfc690a2c1df297] schema migrations work as instances
local:rails matt$ git bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[8b2f801ed8690dcbc61d62e6b3518efaac70a4a4] converted migrations to support instance methods
local:rails matt$ git bisect bad
8b2f801ed8690dcbc61d62e6b3518efaac70a4a4 is the first bad commit
commit 8b2f801ed8690dcbc61d62e6b3518efaac70a4a4
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Wed Nov 17 12:53:38 2010 -0800

    converted migrations to support instance methods

:040000 040000 8e4adf421f6b9d8e6d696ac9526319b8e71bb486 cf3def12c0e5c1e92393f7293a5c5c9637d5af8f M  activerecord

If it’s a relatively simple bug to isolate, look into git bisect run–it makes the process entirely automated.

(Oh, and by the way, if anyone is running into the same problem I did, ActiveRecord::Base.connection is now ActiveRecord::Base#connection. In other words, it’s now an instance method, not a class method.)

Like this post? You might also like Coalmine, my centralized error tracking service for your apps. Coalmine captures errors and all kinds of helpful debugging information, notifies you, and makes it all searchable. Check it out!

15
Nov 10

Edge Rails pro-tip!

When using edge Rails, you should use edge Arel and edge Rack, also. Otherwise you’ll get weird bugs.

gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel',  :git => 'git://github.com/rails/arel.git'
gem 'rack',  :git => 'git://github.com/rack/rack.git'
Like this post? You might also like Coalmine, my centralized error tracking service for your apps. Coalmine captures errors and all kinds of helpful debugging information, notifies you, and makes it all searchable. Check it out!

29
Oct 10

Edge Rails and Bundler

I needed some Rails 3.1 enhancements to Rails Engines for an in-development app, so I enabled Edge Rails in my Gemfile:

gem 'rails', :git => 'git://github.com/rails/rails.git'

Then I did what I normally do, sudo bundle install. But this broke the rails command—why?

I deleted the Git checkout and tried again:

$ sudo bundle install
Fetching git://github.com/rails/rails.git
remote: Counting objects: 195841, done.
remote: Compressing objects: 100% (42932/42932), done.
remote: Total 195841 (delta 151525), reused 195056 (delta 150929)
Receiving objects: 100% (195841/195841), 33.12 MiB | 2.05 MiB/s, done.
Resolving deltas: 100% (151525/151525), done.
Fetching source index for http://rubygems.org/
[...]
Using rails (3.1.0.beta) from git://github.com/rails/rails.git (at master)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
$ bundle show
git://github.com/rails/rails.git (at master) is not checked out. Please run `bundle install`

Although Bundler has had some issues with remote Git repositories in the past, this one was entirely my fault: don’t use sudo bundle install. A simple check confirms this: sudo bundle show works like you’d expect.

So to recap: remove the checkout and bundle install (no sudo!) to fix this problem.

Like this post? You might also like Coalmine, my centralized error tracking service for your apps. Coalmine captures errors and all kinds of helpful debugging information, notifies you, and makes it all searchable. Check it out!