Skip to content

Commit 03e3b78

Browse files
authored
Merge pull request #9164 from eregon/fix-broken-config-recommendation-in-default-command-warning
Fix the config suggestion in the warning for `$ bundle`
2 parents 38f6519 + 979dada commit 03e3b78

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

bundler/lib/bundler/cli.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,31 @@ def cli_help
120120
self.class.send(:class_options_help, shell)
121121
end
122122

123-
desc "install_or_cli_help", "Tries to run bundle install but prints a summary of bundler commands if there is no Gemfile", hide: true
123+
desc "install_or_cli_help", "Deprecated alias of install", hide: true
124124
def install_or_cli_help
125+
Bundler.ui.warn <<~MSG
126+
`bundle install_or_cli_help` is a deprecated alias of `bundle install`.
127+
It might be called due to the 'default_cli_command' being set to 'install_or_cli_help',
128+
if so fix that by running `bundle config set default_cli_command install --global`.
129+
MSG
125130
invoke_other_command("install")
126-
rescue GemfileNotFound => error
127-
Bundler.ui.error error.message, wrap: true
128-
invoke_other_command("cli_help")
129131
end
130132

131133
def self.default_command(meth = nil)
132134
return super if meth
133135

134136
unless Bundler.settings[:default_cli_command]
135-
Bundler.ui.info <<-MSG
137+
Bundler.ui.info <<~MSG
136138
In a future version of Bundler, running `bundle` without argument will no longer run `bundle install`.
137139
Instead, the `cli_help` command will be displayed. Please use `bundle install` explicitly for scripts like CI/CD.
138140
You can use the future behavior now with `bundle config set default_cli_command cli_help --global`,
139-
or you can continue to use the current behavior with `bundle config set default_cli_command install_or_cli_help --global`.
141+
or you can continue to use the current behavior with `bundle config set default_cli_command install --global`.
140142
This message will be removed after a default_cli_command value is set.
143+
141144
MSG
142145
end
143146

144-
Bundler.settings[:default_cli_command] || "install_or_cli_help"
147+
Bundler.settings[:default_cli_command] || "install"
145148
end
146149

147150
class_option "no-color", type: :boolean, desc: "Disable colorization in output"
@@ -287,6 +290,9 @@ def install
287290
Bundler.settings.temporary(no_install: false) do
288291
Install.new(options).run
289292
end
293+
rescue GemfileNotFound => error
294+
invoke_other_command("cli_help")
295+
raise error # re-raise to show the error and get a failing exit status
290296
end
291297

292298
map aliases_for("install")

bundler/spec/bundler/cli_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ def out_with_macos_man_workaround
100100
end
101101

102102
it "runs bundle install when default_cli_command set to install" do
103-
bundle "config set default_cli_command install_or_cli_help"
103+
bundle "config set default_cli_command install"
104104
bundle "", raise_on_error: false
105105
expect(out).to_not include("In a future version of Bundler")
106106
expect(err).to include("Could not locate Gemfile")
107+
expect(exitstatus).to_not be_zero
107108
end
108109
end
109110

0 commit comments

Comments
 (0)