Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do bundler update the gem incase of gems pointed to git repo?

I am trying to move the common functionality of 3 Rails application into a gem. I have created the gem, tested it locally and is going to move to a private repository.

So, now I am concerned about how to deal with case if I have change in the code inside the gem. Do I need to change the version of the gem, if I want to update the gem while bundle update mygem, or will Bundler detect the change from the commit hash of the git repo while doing bundle update mygem?

like image 644
rubyprince Avatar asked Dec 10 '13 06:12

rubyprince


People also ask

How does bundler handle changes to the local Git repository?

Similar to a path source, every time the local git repository change, changes will be automatically picked up by Bundler. This means a commit in the local git repo will update the revision in the Gemfile.lock to the local git repo revision.

How does bundler know when I update my Gemfile?

If you update your Gemfile, and your system already has all of the needed dependencies, bundler will transparently update the Gemfile.lock when you boot your application.

Why is bundler not updating my rack-cache?

In order to avoid this problem, when you update a gem, bundler will not update a dependency of that gem if another gem still depends on it. In this example, since rack-cache still depends on rack, bundler will not update the rack gem. This ensures that updating rails doesn't inadvertently break rack-cache.

How do I install a gem from a git repository?

Bundler has the ability to install gems directly from git repositories. Installing a gem using git is as easy as adding a gem to your Gemfile. Note that because RubyGems lacks the ability to handle gems from git, any gems installed from a git repository will not show up in gem list . They will, however, be available after running Bundler.setup .


2 Answers

You do not need to change the version inside the gem every time you make a change to it. When using git gems, Gemfile.lock locks to a commit hash rather than the version number. You don't need to specify a version at all.

When you run bundle update mygem and mygem is a git gem, it will update the locked commit hash to the latest available on the branch you have specified (or on master if you have not specified a branch).

like image 84
Tim Moore Avatar answered Nov 03 '22 01:11

Tim Moore


Since your Gemfile will be referencing your gem in the private git repository, then in order for your application to pick up any new changes in your gem, you need to do bundle update gemname. Pure and simple. If you do not do that, bundle will not pick up the changes.

Bundler uses the version of your gem that is locked inside your Gemfile.lock file in order to start/use it in your application. The version info inside your Gemfile.lock is updated only if you do bundle update. Otherwise it is locked (a.k.a. Gemfile.lock) and whatever version is locked is being used.

BTW, referencing a gem in a private git repository can have many options (:branch, :tag e.t.c.) but this is irrelevant. Lock is going to take place not matter what.

I hope that this one explains how bundler works.

like image 35
p.matsinopoulos Avatar answered Nov 03 '22 00:11

p.matsinopoulos