@@ -241,16 +241,16 @@ def run_bundle_install(bundle_gemfile = @gemfile)
241
241
env
242
242
end
243
243
244
- sig { params ( env : T ::Hash [ String , String ] ) . returns ( T ::Hash [ String , String ] ) }
245
- def run_bundle_install_directly ( env )
244
+ sig { params ( env : T ::Hash [ String , String ] , force_install : T :: Boolean ) . returns ( T ::Hash [ String , String ] ) }
245
+ def run_bundle_install_directly ( env , force_install : false )
246
246
RubyVM ::YJIT . enable if defined? ( RubyVM ::YJIT . enable )
247
247
248
248
# The ENV can only be merged after checking if an update is required because we depend on the original value of
249
249
# ENV["BUNDLE_GEMFILE"], which gets overridden after the merge
250
250
should_update = should_bundle_update?
251
251
T . unsafe ( ENV ) . merge! ( env )
252
252
253
- unless should_update
253
+ unless should_update && ! force_install
254
254
Bundler ::CLI ::Install . new ( { } ) . run
255
255
correct_relative_remote_paths if @custom_lockfile . exist?
256
256
return env
@@ -265,6 +265,9 @@ def run_bundle_install_directly(env)
265
265
correct_relative_remote_paths if @custom_lockfile . exist?
266
266
@last_updated_path . write ( Time . now . iso8601 )
267
267
env
268
+ rescue Bundler ::GemNotFound , Bundler ::GitError
269
+ # If a gem is not installed, skip the upgrade and try to install it with a single retry
270
+ @retry ? env : run_bundle_install_directly ( env , force_install : true )
268
271
end
269
272
270
273
sig { params ( env : T ::Hash [ String , String ] ) . returns ( T ::Hash [ String , String ] ) }
0 commit comments