Skip to content

Commit 41fadbe

Browse files
committed
Fix the config suggestion in the warning for $ bundle
* `install_or_cli_help` does not exist for older Bundler like Bundler 2 and so results in a confusing error on Bundler 2: ``` $ bundle Could not find command "". ``` * See https://github.com/ruby/rubygems/pull/9136/files#r2592366837 * Merge the behavior of `install_or_cli_help` in `install`.
1 parent c00ca53 commit 41fadbe

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

bundler/lib/bundler/cli.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ 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
124-
def install_or_cli_help
125-
invoke_other_command("install")
126-
rescue GemfileNotFound => error
127-
Bundler.ui.error error.message, wrap: true
128-
invoke_other_command("cli_help")
129-
end
130-
131123
def self.default_command(meth = nil)
132124
return super if meth
133125

@@ -136,12 +128,12 @@ def self.default_command(meth = nil)
136128
In a future version of Bundler, running `bundle` without argument will no longer run `bundle install`.
137129
Instead, the `cli_help` command will be displayed. Please use `bundle install` explicitly for scripts like CI/CD.
138130
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`.
131+
or you can continue to use the current behavior with `bundle config set default_cli_command install --global`.
140132
This message will be removed after a default_cli_command value is set.
141133
MSG
142134
end
143135

144-
Bundler.settings[:default_cli_command] || "install_or_cli_help"
136+
Bundler.settings[:default_cli_command] || "install"
145137
end
146138

147139
class_option "no-color", type: :boolean, desc: "Disable colorization in output"
@@ -287,6 +279,9 @@ def install
287279
Bundler.settings.temporary(no_install: false) do
288280
Install.new(options).run
289281
end
282+
rescue GemfileNotFound => error
283+
invoke_other_command("cli_help")
284+
raise error # re-raise to show the error and get a failing exit status
290285
end
291286

292287
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)