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

brittle handling of ENV['BUNDLE_GEMFILE'] #3678

Closed
e2 opened this issue May 27, 2015 · 6 comments
Closed

brittle handling of ENV['BUNDLE_GEMFILE'] #3678

e2 opened this issue May 27, 2015 · 6 comments

Comments

@e2
Copy link
Contributor

e2 commented May 27, 2015

Setting BUNDLE_GEMFILE= (as opposed to unsetting the env variable) causes Bundler to go crazy.

The problem is with these 2 lines here: https://github.com/bundler/bundler/blob/e8c962ef2a3215cdc6fd411b6724f091a16793d6/lib/bundler/cli.rb#L19-L20

When BUNDLE_GEMFILE happens to be "":

  1. custom_gemfile becomes "", which evaluates to true
  2. File.expand_path(custom_gemfile) expands to the current directory and ...
  3. ENV['BUNDLE_GEMFILE'] now contains a directory instead of a file - which causes Bundler to blow up.

Use case: I'm running bundle install as root on one Gemfile, and then running another, unrelated bundle install on another Gemfile - the variable is set and propagated and deleting the env variable is tricky on my setup (my workaround is: /usr/bin/env -u BUNDLE_GEMFILE foo, which isn't portable).

@indirect
Copy link
Member

You're right, and this is a bug. We should fix it. The reason no one else has had this problem, though, is that Bundler provides a way to run commands outside of the current bundle:

Bundler.with_clean_env do
  `cd /other/bundle && bundle install`
end

I'd suggest that as a workaround for now.

@e2
Copy link
Contributor Author

e2 commented May 27, 2015

Ideally, I'd be able to do: BUNDLE_ENV=clean foo or RUBYOPT=-rbundler/clean foo

In my case, I have my hands tied on "both sides" (root and user), because I can't call Ruby code from root context (I don't have access, though process is run through bundle exec as root - which is why the variables are exported) and I can't use Bundler from user's Ruby (because RVM may not be installed yet).

@agis
Copy link
Contributor

agis commented Sep 13, 2015

@indirect Couldn't we just append an additional !custom_gemfile.empty? check in here?

@indirect
Copy link
Member

That sounds good to me.

@agis
Copy link
Contributor

agis commented Sep 13, 2015

Cool, will wrap up a PR with some tests soon.

@e2
Copy link
Contributor Author

e2 commented Sep 16, 2015

Cool, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants