Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when modifying Gemfile.lock directly?

Tags:

ruby

gem

Since the second time of bundle install execution, dependencies are loaded from Gemfile.lock as long as Gemfile isn't changed.

But I wonder how detection of changes is made between those two files.

For instance, if I'm adding a new dependency directly into Gemfile.lock without adding it into Gemfile (as opposed to the best practice since Gemfile.lock is auto-generated from Gemfile), would a bundle install consider Gemfile as changed ?

Indeed, does bundle install process compares the whole Gemfile and Gemfile.lock trees in order to detect changes?

If it is, even if I'm adding a dependency directly to Gemfile.lock, Gemfile would be detected as changed (since different) and would re-erase Gemfile.lock (so losing the added dependency...)

What is the process of bundle install since the launch for the second time ?

To be more clear, my question is:

Are changes based only from Gemfile ? That means bundler would keep a Gemfile snapshot of every bundle install execution number N and merely compares it to the bundle install execution N+1 ?

Or no snapshots are created in bundler memory and bundler makes a comparison with Gemfile.lock each time to detect if Gemfile must be considered as changed.

like image 933
Mik378 Avatar asked Jun 21 '12 09:06

Mik378


People also ask

Can you update Gemfile lock?

Gemfile. lock is automatically generated when you run bundle install or bundle update . It should never be edited manually.

What does the Gemfile lock do?

The Gemfile. lock allows you to specify the versions of the dependencies that your application needs in the Gemfile , while remembering all of the exact versions of third-party code that your application used when it last worked correctly. By specifying looser dependencies in your Gemfile (such as nokogiri ~> 1.4.

Should you commit your Gemfile lock?

You should always include your Gemfile. lock if you are writing an application. The community seems to (largely) agree that you should include it in any Gems you create as well.

What is difference between Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.


1 Answers

If you edit your Gemfile.lock then Rails app would depend on another versions of gems... The integrity of your gem-versioning system would be broken in this case. It's a very-very bad idea to edit Gemfile.lock file directly.

Please, be a good guy and make deals with Gemfile only

like image 95
odiszapc Avatar answered Oct 27 '22 00:10

odiszapc