ruby-changes:61727
From: Josef <ko1@a...>
Date: Mon, 15 Jun 2020 21:21:03 +0900 (JST)
Subject: [ruby-changes:61727] 3ab1cfc325 (master): Add Gem.disable_system_update_message to disable gem update --system if needed.
https://git.ruby-lang.org/ruby.git/commit/?id=3ab1cfc325 From 3ab1cfc325811b862cb81d0360bf83216cd6f235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= <josef.simanek@g...> Date: Sun, 14 Jun 2020 00:26:23 +0200 Subject: Add Gem.disable_system_update_message to disable gem update --system if needed. diff --git a/lib/rubygems.rb b/lib/rubygems.rb index c018492..d24c07d 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -1188,6 +1188,12 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1188 class << self ## + # RubyGems distributors (like operating system package managers) can + # disable RubyGems update by setting this to error message printed to + # end-users on gem update --system instead of actual update. + attr_accessor :disable_system_update_message + + ## # Hash of loaded Gem::Specification keyed by name attr_reader :loaded_specs diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index ca407ee..052d9f9 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -262,6 +262,11 @@ command to remove old versions. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L262 # Update RubyGems software to the latest version. def update_rubygems + if Gem.disable_system_update_message + alert_error Gem.disable_system_update_message + return + end + check_update_arguments version, requirement = rubygems_target_version diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index efaa621..3b823a0 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -238,6 +238,23 @@ class TestGemCommandsUpdateCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_update_command.rb#L238 @ui.error end + def test_execute_system_with_disabled_update + old_disable_system_update_message = Gem.disable_system_update_message + Gem.disable_system_update_message = "Please use package manager instead." + + @cmd.options[:args] = [] + @cmd.options[:system] = true + + use_ui @ui do + @cmd.execute + end + + assert_empty @ui.output + assert_equal "ERROR: Please use package manager instead.\n", @ui.error + ensure + Gem.disable_system_update_message = old_disable_system_update_message + end + # before: # a1 -> c1.2 # after: -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/