summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamden Narzt <[email protected]>2024-12-11 12:29:39 -0700
committergit <[email protected]>2024-12-13 14:23:30 +0000
commit6cde41bc52cb411a3259349b23fab2cd05789b01 (patch)
tree2ec7d79ff2e2efbda1730ba49398d96bb4a8e48b
parent3cb79d408253cd4f60c2bd0a69ceedfc424b63e8 (diff)
[rubygems/rubygems] Fix restarting with locked version when $PROGRAM_NAME has been changed
Use Process.argv0 instead of $PROGRAM_NAME because $PROGRAM_NAME is liable to be changed but Process.argv0 is not. https://github.com/rubygems/rubygems/commit/43b747dc9e
-rw-r--r--lib/bundler/self_manager.rb4
-rw-r--r--spec/bundler/runtime/self_management_spec.rb19
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/bundler/self_manager.rb b/lib/bundler/self_manager.rb
index 6ab41b99f7..b88faf7589 100644
--- a/lib/bundler/self_manager.rb
+++ b/lib/bundler/self_manager.rb
@@ -84,8 +84,8 @@ module Bundler
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
diff --git a/spec/bundler/runtime/self_management_spec.rb b/spec/bundler/runtime/self_management_spec.rb
index f00e6cba45..7804f5991f 100644
--- a/spec/bundler/runtime/self_management_spec.rb
+++ b/spec/bundler/runtime/self_management_spec.rb
@@ -194,6 +194,25 @@ RSpec.describe "Self management" do
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)