Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Bundler cannot add multiple gems from the same git source #7346

Closed
ajorgensen opened this issue Sep 6, 2019 · 2 comments · Fixed by #7419
Closed

Bundler cannot add multiple gems from the same git source #7346

ajorgensen opened this issue Sep 6, 2019 · 2 comments · Fixed by #7419

Comments

@ajorgensen
Copy link

I've created a POC project for this behavior (https://github.com/ajorgensen/bundler-poc) but I will also summarize the behavior here.

Essentially if you have a Gemfile with multiple gems coming from the same git source but with different subfolders then bundle install will error out because it cannot find the dependency. The most simple example I could come up with was:

source 'https://rubygems.org'

gem 'base_gem', git: 'git@github.com:ajorgensen/bundler-poc.git', glob: 'gems/base_gem/*.gemspec'
gem 'some_gem', git: 'git@github.com:ajorgensen/bundler-poc.git', glob: 'gems/some_gem/*.gemspec'

gemspec

Running bundle install with this gemfile will result in the following error:

Fetching git@github.com:ajorgensen/bundler-poc.git
Fetching gem metadata from https://rubygems.org/
Could not find gem 'base_gem' in git@github.com:ajorgensen/bundler-poc.git (at master@002e6fd).
The source does not contain any versions of 'base_gem'

This is surprising because I would expect that this should work correctly. The workaround I found was to do something like this:

source 'https://rubygems.org'

gem 'base_gem', git: 'git@github.com:ajorgensen/bundler-poc.git', glob: 'gems/**/*.gemspec'
gem 'some_gem', git: 'git@github.com:ajorgensen/bundler-poc.git', glob: 'gems/**/*.gemspec'

gemspec

By simply always including all of the gemspecs I can get bundle install to work correctly.

I did a bit of digging and my hypothesis is that the source is getting added for each of the different gems but the options are getting overwritten because the source itself is the same for both gems. So in the broken case, the source would get added first with the one glob option and then it is added a second time and overwrites the existing glob option. I believe this is happening somewhere around here: https://github.com/bundler/bundler/blob/master/lib/bundler/source_list.rb#L125-L128

I will admit I have very little knowledge of how bundler works but my naive thought would be that sources should be treated separately if they have different options or add in some special logic to merge the two sources so the options like glob aren't overwritten but merged.

I will continue to dig deeper into this and see if I can find an elegant way to fix this behavior but I thought I would put up an issue to see if someone who knows more has a more clever idea.

@deivid-rodriguez
Copy link
Member

Thanks for the clear report @ajorgensen. It looks like a bug to me, yeah!

@deivid-rodriguez
Copy link
Member

@ajorgensen This is being fixed in #7419. Can you give that a try and see if it works for you?

Also, note that the default behavior of bundler is to consider all gemspecs in the git source for resolving (as you noticed). I think this is because normally inside monorepos gems are dependent on each other, so this is what you usually want.

So I think doing

git 'git@github.com:ajorgensen/bundler-poc.git' do
  gem 'base_gem'
  gem 'some_gem'
end

should also do the trick for you.

I can see though how there could be cases were you don't want the default behavior and prefer to be explicit about gemspecs for each gem in the git source. Specially since, even if very niche, the git source already has this :glob option as a feature, so this is arguably a bug.

@ghost ghost closed this as completed in 87449d5 Nov 26, 2019
deivid-rodriguez pushed a commit that referenced this issue Dec 13, 2019
7419: Add :glob to git source uniqueness r=deivid-rodriguez a=fatkodima

Closes #7346

Co-authored-by: fatkodima <fatkodima123@gmail.com>
(cherry picked from commit 87449d5)
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants