Skip to content

Commit

Permalink
Fix restarting with locked version when $PROGRAM_NAME has been changed
Browse files Browse the repository at this point in the history
Use Process.argv0 instead of $PROGRAM_NAME because $PROGRAM_NAME is
liable to be changed but Process.argv0 is not.
  • Loading branch information
CamJN authored and deivid-rodriguez committed Dec 12, 2024
1 parent 3d0a916 commit 43b747d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bundler/lib/bundler/self_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def restart_with(version)
require "shellwords"
cmd = [*Shellwords.shellsplit(bundler_spec_original_cmd), *ARGV]
else
cmd = [$PROGRAM_NAME, *ARGV]
cmd.unshift(Gem.ruby) unless File.executable?($PROGRAM_NAME)
cmd = [Process.argv0, *ARGV]
cmd.unshift(Gem.ruby) unless File.executable?(Process.argv0)
end

Bundler.with_original_env do
Expand Down
19 changes: 19 additions & 0 deletions bundler/spec/runtime/self_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,25 @@
expect(out).to include("Using bundler #{Bundler::VERSION}")
end

it "uses the right original script when re-execing, even if `$0` has been changed", :ruby_repo do
bundle "config path vendor/bundle"

system_gems "bundler-9.9.9", path: vendored_gems

test = bundled_app("test.rb")

create_file test, <<~RUBY
$0 = "this is the program name"
require "bundler/setup"
RUBY

lockfile_bundled_with("9.9.9")

sys_exec "#{Gem.ruby} #{test}", artifice: nil, raise_on_error: false
expect(err).to include("Could not find myrack-1.0.0")
expect(err).not_to include("this is the program name")
end

private

def lockfile_bundled_with(version)
Expand Down

0 comments on commit 43b747d

Please sign in to comment.