Skip to content

Commit 80c1e7e

Browse files
Merge pull request #8320 from CamJN/patch-1
Fix restarting with locked version when `$PROGRAM_NAME` has been changed
2 parents 3d0a916 + 43b747d commit 80c1e7e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

bundler/lib/bundler/self_manager.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def restart_with(version)
8484
require "shellwords"
8585
cmd = [*Shellwords.shellsplit(bundler_spec_original_cmd), *ARGV]
8686
else
87-
cmd = [$PROGRAM_NAME, *ARGV]
88-
cmd.unshift(Gem.ruby) unless File.executable?($PROGRAM_NAME)
87+
cmd = [Process.argv0, *ARGV]
88+
cmd.unshift(Gem.ruby) unless File.executable?(Process.argv0)
8989
end
9090

9191
Bundler.with_original_env do

bundler/spec/runtime/self_management_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,25 @@
194194
expect(out).to include("Using bundler #{Bundler::VERSION}")
195195
end
196196

197+
it "uses the right original script when re-execing, even if `$0` has been changed", :ruby_repo do
198+
bundle "config path vendor/bundle"
199+
200+
system_gems "bundler-9.9.9", path: vendored_gems
201+
202+
test = bundled_app("test.rb")
203+
204+
create_file test, <<~RUBY
205+
$0 = "this is the program name"
206+
require "bundler/setup"
207+
RUBY
208+
209+
lockfile_bundled_with("9.9.9")
210+
211+
sys_exec "#{Gem.ruby} #{test}", artifice: nil, raise_on_error: false
212+
expect(err).to include("Could not find myrack-1.0.0")
213+
expect(err).not_to include("this is the program name")
214+
end
215+
197216
private
198217

199218
def lockfile_bundled_with(version)

0 commit comments

Comments
 (0)