From 607648d5fc98782018a40c45079d300c48f684c4 Mon Sep 17 00:00:00 2001 From: Shinichi Maeshima Date: Wed, 29 Apr 2026 19:11:00 +0900 Subject: [ruby/rubygems] Make `bundle config get` return status 1 when the value is not set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix https://github.com/ruby/rubygems/pull/3215 Change the exit status to 1 when trying to `get` a config key that does not exist, as shown below. ```sh $ bundle config get foo Settings for `foo` in order of priority. The top value will be used You have not configured a value for `foo` $ echo $? 1 ``` It seems that showing “Settings for `foo` in order of priority. The top value will be used” when the key does not exist is not very meaningful, but for now I have left the behavior unchanged except for the exit status. In the tests, some existing cases try to `get` a missing config without `raise_on_error: false`, so set the value in advance or add `raise_on_error: false` to handle them. https://github.com/ruby/rubygems/commit/73205e3d64 --- lib/bundler/cli/config.rb | 15 +++++++++++++-- spec/bundler/bundler/cli_spec.rb | 4 +++- spec/bundler/commands/config_spec.rb | 15 ++++++++++----- spec/bundler/other/major_deprecation_spec.rb | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/bundler/cli/config.rb b/lib/bundler/cli/config.rb index 6a77e4a65e..3ac973cfe1 100644 --- a/lib/bundler/cli/config.rb +++ b/lib/bundler/cli/config.rb @@ -88,15 +88,26 @@ module Bundler if value.nil? warn_unused_scope "Ignoring --#{scope} since no value to set was given" + configured = Bundler.settings.locations(name).any? + if options[:parseable] if value = Bundler.settings[name] Bundler.ui.info("#{name}=#{value}") end - return + if configured + return + else + exit 1 + end end confirm(name) - return + + if configured + return + else + exit 1 + end end Bundler.ui.info(message) if message diff --git a/spec/bundler/bundler/cli_spec.rb b/spec/bundler/bundler/cli_spec.rb index d1e6d7d411..56caf9937e 100644 --- a/spec/bundler/bundler/cli_spec.rb +++ b/spec/bundler/bundler/cli_spec.rb @@ -251,8 +251,10 @@ To update to the most recent version, run `bundle update --bundler` context "running a parseable command" do it "prints no warning" do + bundle "config set foo value", env: { "BUNDLER_VERSION" => bundler_version } bundle "config get --parseable foo", env: { "BUNDLER_VERSION" => bundler_version } - expect(stdboth).to eq "" + expect(out).to eq "foo=value" + expect(err).to eq "" bundle "platform --ruby", env: { "BUNDLER_VERSION" => bundler_version }, raise_on_error: false expect(stdboth).to eq "Could not locate Gemfile" diff --git a/spec/bundler/commands/config_spec.rb b/spec/bundler/commands/config_spec.rb index 5cafbe3468..0aaae98ccb 100644 --- a/spec/bundler/commands/config_spec.rb +++ b/spec/bundler/commands/config_spec.rb @@ -313,9 +313,10 @@ RSpec.describe ".bundle/config" do describe "parseable option" do it "prints an empty string" do - bundle "config get foo --parseable" + bundle "config get foo --parseable", raise_on_error: false expect(out).to eq "" + expect(last_command).to be_failure end it "only prints the value of the config" do @@ -501,8 +502,9 @@ E it "get" do ENV["BUNDLE_BAR"] = "bar_val" - bundle "config get foo" + bundle "config get foo", raise_on_error: false expect(out).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" + expect(last_command).to be_failure ENV["BUNDLE_FOO"] = "foo_val" @@ -547,7 +549,8 @@ E bundle "config unset foo" expect(out).to eq "" - expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" + expect(bundle("config get foo", raise_on_error: false)).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" + expect(last_command).to be_failure bundle "config set --local foo 1" bundle "config set --global foo 2" @@ -557,7 +560,8 @@ E expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nSet for the current user (#{home(".bundle/config")}): \"2\"" bundle "config unset foo --global" expect(out).to eq "" - expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" + expect(bundle("config get foo", raise_on_error: false)).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" + expect(last_command).to be_failure bundle "config set --local foo 1" bundle "config set --global foo 2" @@ -567,7 +571,8 @@ E expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nSet for your local app (#{bundled_app(".bundle/config")}): \"1\"" bundle "config unset foo --local" expect(out).to eq "" - expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" + expect(bundle("config get foo", raise_on_error: false)).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`" + expect(last_command).to be_failure bundle "config unset foo --local --global", raise_on_error: false expect(last_command).to be_failure diff --git a/spec/bundler/other/major_deprecation_spec.rb b/spec/bundler/other/major_deprecation_spec.rb index 6eeb70abe5..ab7589d698 100644 --- a/spec/bundler/other/major_deprecation_spec.rb +++ b/spec/bundler/other/major_deprecation_spec.rb @@ -290,7 +290,7 @@ RSpec.describe "major deprecations" do describe "old get interface" do before do - bundle "config waka" + bundle "config waka", raise_on_error: false end it "warns", bundler: "4" do -- cgit v1.2.3