Skip to content

Commit 7a297ad

Browse files
deivid-rodriguezhsbt
authored andcommitted
[rubygems/rubygems] Fix Bundler.original_env['GEM_HOME'] when Bundler is trampolined
ruby/rubygems@4c450eb05e
1 parent bc6b045 commit 7a297ad

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/bundler/self_manager.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,23 @@ def install(spec)
6868

6969
def restart_with(version)
7070
configured_gem_home = ENV["GEM_HOME"]
71+
configured_orig_gem_home = ENV["BUNDLER_ORIG_GEM_HOME"]
7172
configured_gem_path = ENV["GEM_PATH"]
73+
configured_orig_gem_path = ENV["BUNDLER_ORIG_GEM_PATH"]
7274

7375
argv0 = File.exist?($PROGRAM_NAME) ? $PROGRAM_NAME : Process.argv0
7476
cmd = [argv0, *ARGV]
7577
cmd.unshift(Gem.ruby) unless File.executable?(argv0)
7678

7779
Bundler.with_original_env do
7880
Kernel.exec(
79-
{ "GEM_HOME" => configured_gem_home, "GEM_PATH" => configured_gem_path, "BUNDLER_VERSION" => version.to_s },
81+
{
82+
"GEM_HOME" => configured_gem_home,
83+
"BUNDLER_ORIG_GEM_HOME" => configured_orig_gem_home,
84+
"GEM_PATH" => configured_gem_path,
85+
"BUNDLER_ORIG_GEM_PATH" => configured_orig_gem_path,
86+
"BUNDLER_VERSION" => version.to_s,
87+
},
8088
*cmd
8189
)
8290
end

spec/bundler/runtime/self_management_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
bundle "-v"
8383
expect(out).to eq(previous_minor)
8484

85+
# Preserves original gem home when auto-switching
86+
bundle "exec ruby -e 'puts Bundler.original_env[\"GEM_HOME\"]'"
87+
expect(out).to eq(ENV["GEM_HOME"])
88+
8589
# ruby-core test setup has always "lib" in $LOAD_PATH so `require "bundler/setup"` always activate the local version rather than using RubyGems gem activation stuff
8690
unless ruby_core?
8791
# App now uses locked version, even when not using the CLI directly

0 commit comments

Comments
 (0)