How to Use a Branch in a Fork of Rails in a Project with Bundler

How to use a branch in a fork of rails in a project with bundler

balu's answer pointed me to the right course, but here are some more details:

It was necessary to cobble together .gemspec files for most of the gems in the rails repo/2-3-stable branch - my take can be seen or forked at http://github.com/traveliq/rails/commit/46d9042c9125abbbedfc672f8523d81210f4f320

To include that in a Gemfile, use:

git "git://github.com/traveliq/rails.git", :branch => 'tiq-fixes' do
gem 'rails'
gem 'actionmailer'
gem 'actionpack'
gem 'activerecord'
gem 'activeresource'
gem 'activesupport'
end

Note that you can't use 'railties', that only defines the 'rails' gem.

Incidentally, while working on this, it was way easier to point the Gemfile at my local repo, which is done this way (rails being the folder where the repo is cloned, a level down from the Gemfile):

gem 'rails',            :path => 'rails/railties'
gem 'actionmailer', :path => 'rails/actionmailer'
gem 'actionpack', :path => 'rails/actionpack'
gem 'activerecord', :path => 'rails/activerecord'
gem 'activesupport', :path => 'rails/activesupport'

After defining the rails/railties .gemspec, you could also leave out some of those gems, and have bundler use the normally available versions from gemcutter etc.

Forking a gem for a Rails project

Today this is pretty easy to do with Bundler. You make a local copy of the gem and then instead of doing

gem "whatever"

in your Gemfile, you do:

gem "whatever", :path => "/home/pupeno/whatever"

After running bundle install, the gem is picked from that directory. Even if you modify something in there, all you need to do to re-load it is restart Rails.

If you need to deploy an application using your own changes of a Gem, you make a fork, on Github or similar and on the Gemfile you do:

gem "whatever", :git => "git@github.com:/pupeno/whatever.git"

and that's it. It's simple, straightforward and beautiful.

Using forked (and patched) Rails 2-3-stable from git woes

So, I solved the patch issue by MonekyPatching ActiveRecord::Base. I reverted the changes to the Gemfile, I'm using Rails 2.3.14 from Rubygems.org now and not from my git fork, and I created an initializer in config/initializers, and pasted the following code: pastie.org/4087875. Now, the application is using the fixed method from the patch (seclists.org/oss-sec/2012/q2/att-504/2-3-sql-injection.patch). However, I'd still like to know why the fork approach did not work, so if someone could shed some light, I'd be grateful.

How to properly pull in git patches for Rails, etc. while not part of the main project?

Put this into your Gemfile

gem rails, :git => "git://github.com/rails/rails.git", :branch => "master"

And run bundle update rails when you need to pull latest changes. It is quite common pattern and you can use it for any gem.

bundle install not working on rails fork

OK, you want to go this route then: https://github.com/rails/rails-dev-box ... the rails repo can't be installed with bundler during active development.

correct way of handling rvm, bundle, git, and branches

In theory, you should only need to run bundle install when you add new gems to the Gemfile.

RVM should not come into this at all, unless you're testing on multiple versions of Ruby simultaneously.

In regard to branches, what I usually do is, having forked the repository, creating branches for large features. Once done, I issue a pull request for that branch, and once accepted I merge that into my local fork, rinse and repeat.

How to clone a gem, fix it, add it to repo, bundle, and deploy with Rails

Steps

  1. Fork the project under your account on Github

  2. Make the changes you want

  3. Use gem 'gem_name', git: 'your_forked_project', branch: 'the_branch_you_working_on'

  4. Run bundle install

how do I install edge rails?

All you have to do is run rake rails:freeze:edge in your project.

Another option if you haven't started your project yet is this:

mkdir -p foo/vendor
cd foo
git clone git://github.com/rails/rails.git vendor/rails
ruby vendor/rails/railties/bin/rails .

or, if you're planning to use git for your project:

mkdir -p foo/vendor
cd foo
git init
git submodule add git://github.com/rails/rails.git vendor/rails
git commit -m "Added Rails Edge as submodule"
ruby vendor/rails/railties/bin/rails .

How to deal with forked gems and bundle

Gemfile.lock should know what gem to load, when you do bundle update or installing a new gem, Gemfile.lock will be updated too with new gems, paths, etc.. and also the revision hash.

The hash at the end of the Fetch/Push URL that you see when you run git remote show origin must be the same as the revision from Gemfile.lock.

For example in my case with active-admin gem in Gemfile.lock I have:

GIT
remote: git://github.com/gregbell/active_admin.git
revision: b7e8c7dde2c26a47e5db0dd1efc163405afadd9d
specs:
activeadmin (1.0.0.pre)
...

even if I have 2 active-admin gems, there is only one with revision: b7e8c7dde2c26a47e5db0dd1efc163405afadd9d

However, working with forks, this what I do:

I usually fork it, pull the froked gem on my computer, update the Gemfile of my app to use the gem from local-storage with path parameter, and I can update the gem without pushing it to github everytime I do a small change just to test it.

When I make it work as I needed, I push it to github and change the path in Gemfile of my app, run bundle again to update the path Gemfile.lock and I am all set. At least here you are not confused what gem the app is loading.



Related Topics



Leave a reply



Submit