Reputation: 1171
My suite of Rails 4.2 apps and gems are currently being upgraded to Rails 5. Is there a way to maintain 2 seperate Gemfiles and Gemfiles - one for Rails 4.2 and another for Rails 5, and push this off to git, so multiple people can work on the apps in both Rails 4.2 and Rails 5?
Upvotes: 0
Views: 99
Reputation: 2226
The usual answer is branches. I'm assuming here that you have a suite of gems that are in development and being upgraded, and one or many "main projects" that depend on these gems, also both in active development and being upgraded.
So for the gems, while developing your rails 5 version, you might have a branch master
and a branch rails-4
. Master, being the bleeding edge, gets upgraded. New feature development can be done in rails-4, and regularly merged into master.
Then, in your main projects, you do the same. Before you create your new branch, you can specify in your main projects' Gemfiles that they should use a particular branch, for example:
gem 'mygem', :git => 'https://github.com/my/gem.git', :branch => 'rails-4'
Then, your main projects can create their own rails-4 branch. On master, you re-edit your Gemfile to return it to pointing to master.
Again, new feature development can continue in the rails-4 branch, and be merged into master until master is ready for production. Once you've shipped the rails 5 versions and everyone is happy, the rails-4 branch can be deleted.
[Edit]: If, for whatever reason, you're averse to git branches, I have seen a growing trend of library writers adding a "gemfiles/" folder to their projects.
My suggestion would be to populate that folder with all the different versions of Gemfiles in your project, then delete the Gemfile from the root using git rm Gemfile
. Also, add the lines /Gemfile
and /Gemfile.lock
to your .gitignore. Commit this change.
Then, when a new developer checks out your repo, they need to link to the Gemfile they wish to use. After linking to the file they want, e.g. ln -s gemfiles/Gemfile-rails-4 Gemfile
they should be able to run bundle install
I should note that I've never done this before - but that would be the general strategy. The branching would still be recommended in the general case - that way, you avoid conditionals in your code, and avoid leftover 'cruft' from the upgrade process.
Upvotes: 1