From 606f91312137465562a6edb86285981f2d5ae8c5 Mon Sep 17 00:00:00 2001 From: Shinichi Maeshima Date: Wed, 29 Apr 2026 19:11:00 +0900 Subject: [PATCH] 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 #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. --- bundler/lib/bundler/cli/config.rb | 15 +++++++++++++-- spec/bundler/cli_spec.rb | 4 +++- spec/commands/config_spec.rb | 15 ++++++++++----- spec/other/major_deprecation_spec.rb | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/bundler/lib/bundler/cli/config.rb b/bundler/lib/bundler/cli/config.rb index 6a77e4a65ea3..3ac973cfe181 100644 --- a/bundler/lib/bundler/cli/config.rb +++ b/bundler/lib/bundler/cli/config.rb @@ -88,15 +88,26 @@ def run 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/cli_spec.rb b/spec/bundler/cli_spec.rb index d1e6d7d411d7..56caf9937e29 100644 --- a/spec/bundler/cli_spec.rb +++ b/spec/bundler/cli_spec.rb @@ -251,8 +251,10 @@ def out_with_macos_man_workaround 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/commands/config_spec.rb b/spec/commands/config_spec.rb index 954cae09d846..30fceed0d158 100644 --- a/spec/commands/config_spec.rb +++ b/spec/commands/config_spec.rb @@ -313,9 +313,10 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index 6eeb70abe50b..ab7589d698d2 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -290,7 +290,7 @@ describe "old get interface" do before do - bundle "config waka" + bundle "config waka", raise_on_error: false end it "warns", bundler: "4" do