From 747aecbb7442304ddee4b6aef1d973327d63ec27 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 18 Aug 2023 12:10:47 +0900 Subject: [PATCH] Merge RubyGems-3.4.19 and Bundler-2.4.19 --- lib/bundler.rb | 2 +- lib/bundler/cli/binstubs.rb | 2 +- lib/bundler/cli/info.rb | 2 +- lib/bundler/cli/install.rb | 2 +- lib/bundler/cli/outdated.rb | 2 +- lib/bundler/cli/platform.rb | 12 +-- lib/bundler/definition.rb | 45 +++++----- lib/bundler/dsl.rb | 2 +- lib/bundler/env.rb | 2 +- lib/bundler/fetcher.rb | 12 ++- lib/bundler/fetcher/compact_index.rb | 6 +- lib/bundler/fetcher/downloader.rb | 2 + lib/bundler/fetcher/index.rb | 3 +- lib/bundler/friendly_errors.rb | 2 +- lib/bundler/gem_helper.rb | 7 +- lib/bundler/installer/parallel_installer.rb | 2 +- lib/bundler/man/bundle-add.1 | 2 +- lib/bundler/man/bundle-binstubs.1 | 2 +- lib/bundler/man/bundle-cache.1 | 2 +- lib/bundler/man/bundle-check.1 | 2 +- lib/bundler/man/bundle-clean.1 | 2 +- lib/bundler/man/bundle-config.1 | 2 +- lib/bundler/man/bundle-console.1 | 2 +- lib/bundler/man/bundle-doctor.1 | 2 +- lib/bundler/man/bundle-exec.1 | 2 +- lib/bundler/man/bundle-gem.1 | 2 +- lib/bundler/man/bundle-help.1 | 2 +- lib/bundler/man/bundle-info.1 | 6 +- lib/bundler/man/bundle-info.1.ronn | 6 +- lib/bundler/man/bundle-init.1 | 2 +- lib/bundler/man/bundle-inject.1 | 2 +- lib/bundler/man/bundle-install.1 | 2 +- lib/bundler/man/bundle-list.1 | 2 +- lib/bundler/man/bundle-lock.1 | 2 +- lib/bundler/man/bundle-open.1 | 2 +- lib/bundler/man/bundle-outdated.1 | 2 +- lib/bundler/man/bundle-platform.1 | 2 +- lib/bundler/man/bundle-plugin.1 | 2 +- lib/bundler/man/bundle-pristine.1 | 2 +- lib/bundler/man/bundle-remove.1 | 2 +- lib/bundler/man/bundle-show.1 | 2 +- lib/bundler/man/bundle-update.1 | 2 +- lib/bundler/man/bundle-version.1 | 2 +- lib/bundler/man/bundle-viz.1 | 2 +- lib/bundler/man/bundle.1 | 2 +- lib/bundler/man/gemfile.5 | 15 +++- lib/bundler/man/gemfile.5.ronn | 5 ++ lib/bundler/plugin/index.rb | 2 +- lib/bundler/ruby_dsl.rb | 6 ++ lib/bundler/ruby_version.rb | 4 +- lib/bundler/rubygems_integration.rb | 2 +- lib/bundler/source/git.rb | 7 ++ lib/bundler/source_list.rb | 4 - lib/bundler/ui/rg_proxy.rb | 2 +- lib/bundler/version.rb | 2 +- lib/rubygems.rb | 5 +- lib/rubygems/bundler_version_finder.rb | 2 +- lib/rubygems/gemcutter_utilities.rb | 3 +- lib/rubygems/package.rb | 3 +- lib/rubygems/request_set/lockfile/parser.rb | 2 +- lib/rubygems/specification.rb | 4 +- lib/rubygems/user_interaction.rb | 4 +- .../bundler/fetcher/downloader_spec.rb | 10 +++ spec/bundler/bundler/fetcher/index_spec.rb | 23 +---- spec/bundler/bundler/ruby_dsl_spec.rb | 27 +++++- .../install/gems/compact_index_spec.rb | 9 ++ spec/bundler/lock/lockfile_spec.rb | 86 +++++++++++++++++++ ...mpact_index_strict_basic_authentication.rb | 2 +- .../endpoint_strict_basic_authentication.rb | 2 +- spec/bundler/support/artifice/vcr.rb | 2 +- test/rubygems/helper.rb | 2 +- 71 files changed, 280 insertions(+), 126 deletions(-) diff --git a/lib/bundler.rb b/lib/bundler.rb index a31eeebd6111b2..f83268e9cda14d 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -524,7 +524,7 @@ def load_gemspec(file, validate = false) @gemspec_cache[key] ||= load_gemspec_uncached(file, validate) # Protect against caching side-effected gemspecs by returning a # new instance each time. - @gemspec_cache[key].dup if @gemspec_cache[key] + @gemspec_cache[key]&.dup end def load_gemspec_uncached(file, validate = false) diff --git a/lib/bundler/cli/binstubs.rb b/lib/bundler/cli/binstubs.rb index 88d071571f6c90..fc2fad47a554ef 100644 --- a/lib/bundler/cli/binstubs.rb +++ b/lib/bundler/cli/binstubs.rb @@ -11,7 +11,7 @@ def initialize(options, gems) def run Bundler.definition.validate_runtime! path_option = options["path"] - path_option = nil if path_option && path_option.empty? + path_option = nil if path_option&.empty? Bundler.settings.set_command_option :bin, path_option if options["path"] Bundler.settings.set_command_option_if_given :shebang, options["shebang"] installer = Installer.new(Bundler.root, Bundler.definition) diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 0545ce8c75005d..36c7a58f122a7e 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -33,7 +33,7 @@ def spec_for_gem(gem_name) def default_gem_spec(gem_name) return unless Gem::Specification.respond_to?(:find_all_by_name) gem_spec = Gem::Specification.find_all_by_name(gem_name).last - return gem_spec if gem_spec && gem_spec.respond_to?(:default_gem?) && gem_spec.default_gem? + return gem_spec if gem_spec&.default_gem? end def spec_not_found(gem_name) diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 1765621cb32a7b..c71bcf159f0861 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -154,7 +154,7 @@ def normalize_settings end bin_option = options["binstubs"] - bin_option = nil if bin_option && bin_option.empty? + bin_option = nil if bin_option&.empty? Bundler.settings.set_command_option :bin, bin_option if options["binstubs"] Bundler.settings.set_command_option_if_given :shebang, options["shebang"] diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 12c3384938e29b..68c701aefbbbd6 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -194,7 +194,7 @@ def print_gem(current_spec, active_spec, dependency, groups) end current_version = "#{current_spec.version}#{current_spec.git_version}" - if dependency && dependency.specific? + if dependency&.specific? dependency_version = %(, requested #{dependency.requirement}) end diff --git a/lib/bundler/cli/platform.rb b/lib/bundler/cli/platform.rb index 73da8cf80e45ef..32d68abbb19203 100644 --- a/lib/bundler/cli/platform.rb +++ b/lib/bundler/cli/platform.rb @@ -8,12 +8,12 @@ def initialize(options) end def run - platforms, ruby_version = Bundler.ui.silence do - locked_ruby_version = Bundler.locked_gems && Bundler.locked_gems.ruby_version&.gsub(/p\d+\Z/, "") - gemfile_ruby_version = Bundler.definition.ruby_version && Bundler.definition.ruby_version.single_version_string - [Bundler.definition.platforms.map {|p| "* #{p}" }, - locked_ruby_version || gemfile_ruby_version] + ruby_version = if Bundler.locked_gems + Bundler.locked_gems.ruby_version&.gsub(/p\d+\Z/, "") + else + Bundler.definition.ruby_version&.single_version_string end + output = [] if options[:ruby] @@ -23,6 +23,8 @@ def run output << "No ruby version specified" end else + platforms = Bundler.definition.platforms.map {|p| "* #{p}" } + output << "Your platform is: #{Gem::Platform.local}" output << "Your app has gems that work on these platforms:\n#{platforms.join("\n")}" diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 71181ea6e0d4de..564530a98cdf1a 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -390,8 +390,8 @@ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false) both_sources.each do |name, (dep, lock_dep)| next if dep.nil? || lock_dep.nil? - gemfile_source = dep.source || sources.default_source - lock_source = lock_dep.source || sources.default_source + gemfile_source = dep.source || default_source + lock_source = lock_dep.source || default_source next if lock_source.include?(gemfile_source) gemfile_source_name = dep.source ? gemfile_source.to_gemfile : "no specified source" @@ -671,8 +671,8 @@ def converge_locals Bundler.settings.local_overrides.map do |k, v| spec = @dependencies.find {|s| s.name == k } - source = spec && spec.source - if source && source.respond_to?(:local_override!) + source = spec&.source + if source&.respond_to?(:local_override!) source.unlock! if @unlock[:gems].include?(spec.name) locals << [source, source.local_override!(v)] end @@ -805,26 +805,27 @@ def converge_locked_specs def converge_specs(specs) converged = [] - - deps = @dependencies.select do |dep| - specs[dep].any? {|s| s.satisfies?(dep) && (!dep.source || s.source.include?(dep.source)) } - end + deps = [] @specs_that_changed_sources = [] specs.each do |s| + name = s.name dep = @dependencies.find {|d| s.satisfies?(d) } + lockfile_source = s.source - # Replace the locked dependency's source with the equivalent source from the Gemfile - s.source = if dep && dep.source - gemfile_source = dep.source - lockfile_source = s.source + if dep + gemfile_source = dep.source || default_source @specs_that_changed_sources << s if gemfile_source != lockfile_source + deps << dep if !dep.source || lockfile_source.include?(dep.source) + @unlock[:gems] << name if lockfile_source.include?(dep.source) && lockfile_source != gemfile_source - gemfile_source + # Replace the locked dependency's source with the equivalent source from the Gemfile + s.source = gemfile_source else - sources.get_with_fallback(s.source) + # Replace the locked dependency's source with the default source, if the locked source is no longer in the Gemfile + s.source = default_source unless sources.get(lockfile_source) end next if @unlock[:sources].include?(s.source.name) @@ -833,9 +834,9 @@ def converge_specs(specs) if s.source.instance_of?(Source::Path) || s.source.instance_of?(Source::Gemspec) new_specs = begin s.source.specs - rescue PathError, GitError + rescue PathError # if we won't need the source (according to the lockfile), - # don't error if the path/git source isn't available + # don't error if the path source isn't available next if specs. for(requested_dependencies, false). none? {|locked_spec| locked_spec.source == s.source } @@ -849,11 +850,11 @@ def converge_specs(specs) else # If the spec is no longer in the path source, unlock it. This # commonly happens if the version changed in the gemspec - @unlock[:gems] << s.name + @unlock[:gems] << name end end - if dep.nil? && requested_dependencies.find {|d| s.name == d.name } + if dep.nil? && requested_dependencies.find {|d| name == d.name } @unlock[:gems] << s.name else converged << s @@ -877,7 +878,7 @@ def source_requirements source_requirements = if precompute_source_requirements_for_indirect_dependencies? all_requirements = source_map.all_requirements all_requirements = pin_locally_available_names(all_requirements) if @prefer_local - { :default => sources.default_source }.merge(all_requirements) + { :default => default_source }.merge(all_requirements) else { :default => Source::RubygemsAggregate.new(sources, source_map) }.merge(source_map.direct_requirements) end @@ -886,7 +887,7 @@ def source_requirements source_requirements[dep.name] = sources.metadata_source end - default_bundler_source = source_requirements["bundler"] || sources.default_source + default_bundler_source = source_requirements["bundler"] || default_source if @unlocking_bundler default_bundler_source.add_dependency_names("bundler") @@ -899,6 +900,10 @@ def source_requirements source_requirements end + def default_source + sources.default_source + end + def verify_changed_sources! @specs_that_changed_sources.each do |s| if s.source.specs.search(s.name).empty? diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index e74158a9f52539..03c80a408cc4d0 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -41,7 +41,7 @@ def initialize end def eval_gemfile(gemfile, contents = nil) - expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile && @gemfile.parent) + expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent) original_gemfile = @gemfile @gemfile = expanded_gemfile_path @gemfiles << expanded_gemfile_path diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index 8b2e292fd61c64..7b1152930eff28 100644 --- a/lib/bundler/env.rb +++ b/lib/bundler/env.rb @@ -122,7 +122,7 @@ def self.environment specs = Bundler.rubygems.find_name(name) out << [" #{name}", "(#{specs.map(&:version).join(",")})"] unless specs.empty? end - if (exe = caller.last.split(":").first) && exe =~ %r{(exe|bin)/bundler?\z} + if (exe = caller.last.split(":").first)&.match? %r{(exe|bin)/bundler?\z} shebang = File.read(exe).lines.first shebang.sub!(/^#!\s*/, "") unless shebang.start_with?(Gem.ruby, "/usr/bin/env ruby") diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index e12c15af8a8a24..2119799f688437 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -61,6 +61,16 @@ def initialize(remote_uri) end end + # This error is raised if HTTP authentication is correct, but lacks + # necessary permissions. + class AuthenticationForbiddenError < HTTPError + def initialize(remote_uri) + remote_uri = filter_uri(remote_uri) + super "Access token could not be authenticated for #{remote_uri}.\n" \ + "Make sure it's valid and has the necessary scopes configured." + end + end + # Exceptions classes that should bypass retry attempts. If your password didn't work the # first time, it's not going to the third time. NET_ERRORS = [:HTTPBadGateway, :HTTPBadRequest, :HTTPFailedDependency, @@ -70,7 +80,7 @@ def initialize(remote_uri) :HTTPRequestURITooLong, :HTTPUnauthorized, :HTTPUnprocessableEntity, :HTTPUnsupportedMediaType, :HTTPVersionNotSupported].freeze FAIL_ERRORS = begin - fail_errors = [AuthenticationRequiredError, BadAuthenticationError, FallbackError] + fail_errors = [AuthenticationRequiredError, BadAuthenticationError, AuthenticationForbiddenError, FallbackError] fail_errors << Gem::Requirement::BadRequirementError fail_errors.concat(NET_ERRORS.map {|e| Net.const_get(e) }) end.freeze diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb index 77838f0361ad83..8d30dec4711b7a 100644 --- a/lib/bundler/fetcher/compact_index.rb +++ b/lib/bundler/fetcher/compact_index.rb @@ -15,7 +15,7 @@ def self.compact_index_request(method_name) method.bind(self).call(*args, &blk) rescue NetworkDownError, CompactIndexClient::Updater::MisMatchedChecksumError => e raise HTTPError, e.message - rescue AuthenticationRequiredError + rescue AuthenticationRequiredError, BadAuthenticationError # Fail since we got a 401 from the server. raise rescue HTTPError => e @@ -40,7 +40,7 @@ def specs_for_names(gem_names) deps = begin parallel_compact_index_client.dependencies(remaining_gems) rescue TooManyRequestsError - @bundle_worker.stop if @bundle_worker + @bundle_worker&.stop @bundle_worker = nil # reset it. Not sure if necessary serial_compact_index_client.dependencies(remaining_gems) end @@ -49,7 +49,7 @@ def specs_for_names(gem_names) complete_gems.concat(deps.map(&:first)).uniq! remaining_gems = next_gems - complete_gems end - @bundle_worker.stop if @bundle_worker + @bundle_worker&.stop @bundle_worker = nil # reset it. Not sure if necessary gem_info diff --git a/lib/bundler/fetcher/downloader.rb b/lib/bundler/fetcher/downloader.rb index 28d33f1aed3cbb..3062899e0e7a90 100644 --- a/lib/bundler/fetcher/downloader.rb +++ b/lib/bundler/fetcher/downloader.rb @@ -41,6 +41,8 @@ def fetch(uri, headers = {}, counter = 0) when Net::HTTPUnauthorized raise BadAuthenticationError, uri.host if uri.userinfo raise AuthenticationRequiredError, uri.host + when Net::HTTPForbidden + raise AuthenticationForbiddenError, uri.host when Net::HTTPNotFound raise FallbackError, "Net::HTTPNotFound: #{filtered_uri}" else diff --git a/lib/bundler/fetcher/index.rb b/lib/bundler/fetcher/index.rb index 6bb9fcc1939388..c623647f01cdcc 100644 --- a/lib/bundler/fetcher/index.rb +++ b/lib/bundler/fetcher/index.rb @@ -15,8 +15,7 @@ def specs(_gem_names) raise BadAuthenticationError, remote_uri if remote_uri.userinfo raise AuthenticationRequiredError, remote_uri when /403/ - raise BadAuthenticationError, remote_uri if remote_uri.userinfo - raise AuthenticationRequiredError, remote_uri + raise AuthenticationForbiddenError, remote_uri else raise HTTPError, "Could not fetch specs from #{display_uri} due to underlying error <#{e.message}>" end diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index 71faeaf282387a..39afe8a071c83f 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -95,7 +95,7 @@ def exception_message(error) def serialized_exception_for(e) <<-EOS.gsub(/^ {8}/, "") #{e.class}: #{e.message} - #{e.backtrace && e.backtrace.join("\n ").chomp} + #{e.backtrace&.join("\n ")&.chomp} EOS end diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 0bbd2d9b75bebe..dcf759cdedf4cd 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -21,7 +21,7 @@ def tag_prefix=(prefix) def gemspec(&block) gemspec = instance.gemspec - block.call(gemspec) if block + block&.call(gemspec) gemspec end end @@ -152,8 +152,7 @@ def allowed_push_host def gem_push_host env_rubygems_host = ENV["RUBYGEMS_HOST"] - env_rubygems_host = nil if - env_rubygems_host && env_rubygems_host.empty? + env_rubygems_host = nil if env_rubygems_host&.empty? allowed_push_host || env_rubygems_host || "rubygems.org" end @@ -218,7 +217,7 @@ def sh_with_status(cmd, &block) SharedHelpers.chdir(base) do outbuf = IO.popen(cmd, :err => [:child, :out], &:read) status = $? - block.call(outbuf) if status.success? && block + block&.call(outbuf) if status.success? [outbuf, status] end end diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index 58c5aafa1cb3c8..83a381f592564b 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -96,7 +96,7 @@ def call handle_error if failed_specs.any? @specs ensure - worker_pool && worker_pool.stop + worker_pool&.stop end def check_for_unmet_dependencies diff --git a/lib/bundler/man/bundle-add.1 b/lib/bundler/man/bundle-add.1 index 0f2fb918b9abae..8549855b0ddded 100644 --- a/lib/bundler/man/bundle-add.1 +++ b/lib/bundler/man/bundle-add.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-ADD" "1" "July 2023" "" "" +.TH "BUNDLE\-ADD" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-add\fR \- Add gem to the Gemfile and run bundle install diff --git a/lib/bundler/man/bundle-binstubs.1 b/lib/bundler/man/bundle-binstubs.1 index 71255230005b3d..40c338916a1a17 100644 --- a/lib/bundler/man/bundle-binstubs.1 +++ b/lib/bundler/man/bundle-binstubs.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-BINSTUBS" "1" "July 2023" "" "" +.TH "BUNDLE\-BINSTUBS" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-binstubs\fR \- Install the binstubs of the listed gems diff --git a/lib/bundler/man/bundle-cache.1 b/lib/bundler/man/bundle-cache.1 index 81e267fafb72c0..69b1e1e3dd5b08 100644 --- a/lib/bundler/man/bundle-cache.1 +++ b/lib/bundler/man/bundle-cache.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CACHE" "1" "July 2023" "" "" +.TH "BUNDLE\-CACHE" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-cache\fR \- Package your needed \fB\.gem\fR files into your application diff --git a/lib/bundler/man/bundle-check.1 b/lib/bundler/man/bundle-check.1 index 41323c20300c81..748a37e7d19c21 100644 --- a/lib/bundler/man/bundle-check.1 +++ b/lib/bundler/man/bundle-check.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CHECK" "1" "July 2023" "" "" +.TH "BUNDLE\-CHECK" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-check\fR \- Verifies if dependencies are satisfied by installed gems diff --git a/lib/bundler/man/bundle-clean.1 b/lib/bundler/man/bundle-clean.1 index c4a3f5985cb13d..af8f13cd8996c6 100644 --- a/lib/bundler/man/bundle-clean.1 +++ b/lib/bundler/man/bundle-clean.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CLEAN" "1" "July 2023" "" "" +.TH "BUNDLE\-CLEAN" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-clean\fR \- Cleans up unused gems in your bundler directory diff --git a/lib/bundler/man/bundle-config.1 b/lib/bundler/man/bundle-config.1 index 82e5257253d98d..4442f33105eec2 100644 --- a/lib/bundler/man/bundle-config.1 +++ b/lib/bundler/man/bundle-config.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CONFIG" "1" "July 2023" "" "" +.TH "BUNDLE\-CONFIG" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-config\fR \- Set bundler configuration options diff --git a/lib/bundler/man/bundle-console.1 b/lib/bundler/man/bundle-console.1 index ae133e1a810650..24fff46cecf966 100644 --- a/lib/bundler/man/bundle-console.1 +++ b/lib/bundler/man/bundle-console.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CONSOLE" "1" "July 2023" "" "" +.TH "BUNDLE\-CONSOLE" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-console\fR \- Deprecated way to open an IRB session with the bundle pre\-loaded diff --git a/lib/bundler/man/bundle-doctor.1 b/lib/bundler/man/bundle-doctor.1 index 3cdaa070a3e0ee..57da8216cb5b41 100644 --- a/lib/bundler/man/bundle-doctor.1 +++ b/lib/bundler/man/bundle-doctor.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-DOCTOR" "1" "July 2023" "" "" +.TH "BUNDLE\-DOCTOR" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-doctor\fR \- Checks the bundle for common problems diff --git a/lib/bundler/man/bundle-exec.1 b/lib/bundler/man/bundle-exec.1 index 45f908ff0f1a96..852788db7ada28 100644 --- a/lib/bundler/man/bundle-exec.1 +++ b/lib/bundler/man/bundle-exec.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-EXEC" "1" "July 2023" "" "" +.TH "BUNDLE\-EXEC" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-exec\fR \- Execute a command in the context of the bundle diff --git a/lib/bundler/man/bundle-gem.1 b/lib/bundler/man/bundle-gem.1 index 9bf9db772b50f4..8339b727cea880 100644 --- a/lib/bundler/man/bundle-gem.1 +++ b/lib/bundler/man/bundle-gem.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-GEM" "1" "July 2023" "" "" +.TH "BUNDLE\-GEM" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-gem\fR \- Generate a project skeleton for creating a rubygem diff --git a/lib/bundler/man/bundle-help.1 b/lib/bundler/man/bundle-help.1 index 9aabc10f7dfdfe..9787c2d49f55ec 100644 --- a/lib/bundler/man/bundle-help.1 +++ b/lib/bundler/man/bundle-help.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-HELP" "1" "July 2023" "" "" +.TH "BUNDLE\-HELP" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-help\fR \- Displays detailed help for each subcommand diff --git a/lib/bundler/man/bundle-info.1 b/lib/bundler/man/bundle-info.1 index aff307cdd6e6ce..2cced715202743 100644 --- a/lib/bundler/man/bundle-info.1 +++ b/lib/bundler/man/bundle-info.1 @@ -1,16 +1,16 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-INFO" "1" "July 2023" "" "" +.TH "BUNDLE\-INFO" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-info\fR \- Show information for the given gem in your bundle . .SH "SYNOPSIS" -\fBbundle info\fR [GEM] [\-\-path] +\fBbundle info\fR [GEM_NAME] [\-\-path] . .SH "DESCRIPTION" -Print the basic information about the provided GEM such as homepage, version, path and summary\. +Given a gem name present in your bundle, print the basic information about it such as homepage, version, path and summary\. . .SH "OPTIONS" . diff --git a/lib/bundler/man/bundle-info.1.ronn b/lib/bundler/man/bundle-info.1.ronn index 47e457aa3c8155..cecdeb564f4586 100644 --- a/lib/bundler/man/bundle-info.1.ronn +++ b/lib/bundler/man/bundle-info.1.ronn @@ -3,13 +3,13 @@ bundle-info(1) -- Show information for the given gem in your bundle ## SYNOPSIS -`bundle info` [GEM] +`bundle info` [GEM_NAME] [--path] ## DESCRIPTION -Print the basic information about the provided GEM such as homepage, version, -path and summary. +Given a gem name present in your bundle, print the basic information about it + such as homepage, version, path and summary. ## OPTIONS diff --git a/lib/bundler/man/bundle-init.1 b/lib/bundler/man/bundle-init.1 index 27c7e3e65aaaa8..c7a9a155b53127 100644 --- a/lib/bundler/man/bundle-init.1 +++ b/lib/bundler/man/bundle-init.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-INIT" "1" "July 2023" "" "" +.TH "BUNDLE\-INIT" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-init\fR \- Generates a Gemfile into the current working directory diff --git a/lib/bundler/man/bundle-inject.1 b/lib/bundler/man/bundle-inject.1 index 6fa6a40d37bca8..9e25c290858c69 100644 --- a/lib/bundler/man/bundle-inject.1 +++ b/lib/bundler/man/bundle-inject.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-INJECT" "1" "July 2023" "" "" +.TH "BUNDLE\-INJECT" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-inject\fR \- Add named gem(s) with version requirements to Gemfile diff --git a/lib/bundler/man/bundle-install.1 b/lib/bundler/man/bundle-install.1 index 713b730d8d1382..337683af064d3e 100644 --- a/lib/bundler/man/bundle-install.1 +++ b/lib/bundler/man/bundle-install.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-INSTALL" "1" "July 2023" "" "" +.TH "BUNDLE\-INSTALL" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-install\fR \- Install the dependencies specified in your Gemfile diff --git a/lib/bundler/man/bundle-list.1 b/lib/bundler/man/bundle-list.1 index 278f4744aa658d..1680e6007a029e 100644 --- a/lib/bundler/man/bundle-list.1 +++ b/lib/bundler/man/bundle-list.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-LIST" "1" "July 2023" "" "" +.TH "BUNDLE\-LIST" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-list\fR \- List all the gems in the bundle diff --git a/lib/bundler/man/bundle-lock.1 b/lib/bundler/man/bundle-lock.1 index ed331fada8a0c5..8722c44b3d7d0b 100644 --- a/lib/bundler/man/bundle-lock.1 +++ b/lib/bundler/man/bundle-lock.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-LOCK" "1" "July 2023" "" "" +.TH "BUNDLE\-LOCK" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-lock\fR \- Creates / Updates a lockfile without installing diff --git a/lib/bundler/man/bundle-open.1 b/lib/bundler/man/bundle-open.1 index f821b2d9a976cd..3513f0d09baaef 100644 --- a/lib/bundler/man/bundle-open.1 +++ b/lib/bundler/man/bundle-open.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-OPEN" "1" "July 2023" "" "" +.TH "BUNDLE\-OPEN" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-open\fR \- Opens the source directory for a gem in your bundle diff --git a/lib/bundler/man/bundle-outdated.1 b/lib/bundler/man/bundle-outdated.1 index f16eeb6763eab6..129ff00f589780 100644 --- a/lib/bundler/man/bundle-outdated.1 +++ b/lib/bundler/man/bundle-outdated.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-OUTDATED" "1" "July 2023" "" "" +.TH "BUNDLE\-OUTDATED" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-outdated\fR \- List installed gems with newer versions available diff --git a/lib/bundler/man/bundle-platform.1 b/lib/bundler/man/bundle-platform.1 index 5230749ce82565..5021c46b4c44a0 100644 --- a/lib/bundler/man/bundle-platform.1 +++ b/lib/bundler/man/bundle-platform.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-PLATFORM" "1" "July 2023" "" "" +.TH "BUNDLE\-PLATFORM" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-platform\fR \- Displays platform compatibility information diff --git a/lib/bundler/man/bundle-plugin.1 b/lib/bundler/man/bundle-plugin.1 index 345cb52f9cfd90..ec30e1d0fda85d 100644 --- a/lib/bundler/man/bundle-plugin.1 +++ b/lib/bundler/man/bundle-plugin.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-PLUGIN" "1" "July 2023" "" "" +.TH "BUNDLE\-PLUGIN" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-plugin\fR \- Manage Bundler plugins diff --git a/lib/bundler/man/bundle-pristine.1 b/lib/bundler/man/bundle-pristine.1 index fb36b3f701f73c..af81c48d2b8ae8 100644 --- a/lib/bundler/man/bundle-pristine.1 +++ b/lib/bundler/man/bundle-pristine.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-PRISTINE" "1" "July 2023" "" "" +.TH "BUNDLE\-PRISTINE" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-pristine\fR \- Restores installed gems to their pristine condition diff --git a/lib/bundler/man/bundle-remove.1 b/lib/bundler/man/bundle-remove.1 index 2ea4c5a24719d7..d86cf134bdeb6f 100644 --- a/lib/bundler/man/bundle-remove.1 +++ b/lib/bundler/man/bundle-remove.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-REMOVE" "1" "July 2023" "" "" +.TH "BUNDLE\-REMOVE" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-remove\fR \- Removes gems from the Gemfile diff --git a/lib/bundler/man/bundle-show.1 b/lib/bundler/man/bundle-show.1 index 3bf2e401c58314..aa91176bf22be2 100644 --- a/lib/bundler/man/bundle-show.1 +++ b/lib/bundler/man/bundle-show.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-SHOW" "1" "July 2023" "" "" +.TH "BUNDLE\-SHOW" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-show\fR \- Shows all the gems in your bundle, or the path to a gem diff --git a/lib/bundler/man/bundle-update.1 b/lib/bundler/man/bundle-update.1 index 73c85eac3ce4b3..e4e10ad23b3b41 100644 --- a/lib/bundler/man/bundle-update.1 +++ b/lib/bundler/man/bundle-update.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-UPDATE" "1" "July 2023" "" "" +.TH "BUNDLE\-UPDATE" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-update\fR \- Update your gems to the latest available versions diff --git a/lib/bundler/man/bundle-version.1 b/lib/bundler/man/bundle-version.1 index 3e3bd9bb2813a0..5e3ed44600646e 100644 --- a/lib/bundler/man/bundle-version.1 +++ b/lib/bundler/man/bundle-version.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-VERSION" "1" "July 2023" "" "" +.TH "BUNDLE\-VERSION" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-version\fR \- Prints Bundler version information diff --git a/lib/bundler/man/bundle-viz.1 b/lib/bundler/man/bundle-viz.1 index 49fc73421365a0..d5330ec7549748 100644 --- a/lib/bundler/man/bundle-viz.1 +++ b/lib/bundler/man/bundle-viz.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-VIZ" "1" "July 2023" "" "" +.TH "BUNDLE\-VIZ" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\-viz\fR \- Generates a visual dependency graph for your Gemfile diff --git a/lib/bundler/man/bundle.1 b/lib/bundler/man/bundle.1 index 4eae9321480131..99c65a72b52a9c 100644 --- a/lib/bundler/man/bundle.1 +++ b/lib/bundler/man/bundle.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE" "1" "July 2023" "" "" +.TH "BUNDLE" "1" "August 2023" "" "" . .SH "NAME" \fBbundle\fR \- Ruby Dependency Management diff --git a/lib/bundler/man/gemfile.5 b/lib/bundler/man/gemfile.5 index cb4669dd3f92d4..352fa0f5455e8d 100644 --- a/lib/bundler/man/gemfile.5 +++ b/lib/bundler/man/gemfile.5 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GEMFILE" "5" "July 2023" "" "" +.TH "GEMFILE" "5" "August 2023" "" "" . .SH "NAME" \fBGemfile\fR \- A format for describing gem dependencies for Ruby programs @@ -85,6 +85,19 @@ ruby "3\.1\.2" . .IP "" 0 . +.P +If you wish to derive your Ruby version from a version file (ie \.ruby\-version), you can use the \fBfile\fR option instead\. +. +.IP "" 4 +. +.nf + +ruby file: "\.ruby\-version" +. +.fi +. +.IP "" 0 +. .SS "ENGINE" Each application \fImay\fR specify a Ruby engine\. If an engine is specified, an engine version \fImust\fR also be specified\. . diff --git a/lib/bundler/man/gemfile.5.ronn b/lib/bundler/man/gemfile.5.ronn index 1ce93a251aacbd..6749c33f595f43 100644 --- a/lib/bundler/man/gemfile.5.ronn +++ b/lib/bundler/man/gemfile.5.ronn @@ -69,6 +69,11 @@ should be the Ruby version that the engine is compatible with. ruby "3.1.2" +If you wish to derive your Ruby version from a version file (ie .ruby-version), +you can use the `file` option instead. + + ruby file: ".ruby-version" + ### ENGINE Each application _may_ specify a Ruby engine. If an engine is specified, an diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 6fbd036f3811e6..a2d5eaa38a9b04 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -146,7 +146,7 @@ def hook_plugins(event) # @param [Boolean] is the index file global index def load_index(index_file, global = false) SharedHelpers.filesystem_access(index_file, :read) do |index_f| - valid_file = index_f && index_f.exist? && !index_f.size.zero? + valid_file = index_f&.exist? && !index_f.size.zero? break unless valid_file data = index_f.read diff --git a/lib/bundler/ruby_dsl.rb b/lib/bundler/ruby_dsl.rb index 3b3a0583a5bc85..d054969e8d22cc 100644 --- a/lib/bundler/ruby_dsl.rb +++ b/lib/bundler/ruby_dsl.rb @@ -5,9 +5,15 @@ module RubyDsl def ruby(*ruby_version) options = ruby_version.last.is_a?(Hash) ? ruby_version.pop : {} ruby_version.flatten! + raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil? raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil? + if options[:file] + raise GemfileError, "Cannot specify version when using the file option" if ruby_version.any? + ruby_version << Bundler.read_file(options[:file]).strip + end + if options[:engine] == "ruby" && options[:engine_version] && ruby_version != Array(options[:engine_version]) raise GemfileEvalError, "ruby_version must match the :engine_version for MRI" diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb index 92223c8a01bb22..b5396abb6eb798 100644 --- a/lib/bundler/ruby_version.rb +++ b/lib/bundler/ruby_version.rb @@ -28,8 +28,8 @@ def initialize(versions, patchlevel, engine, engine_version) end @gem_version = Gem::Requirement.create(@versions.first).requirements.first.last - @input_engine = engine && engine.to_s - @engine = engine && engine.to_s || "ruby" + @input_engine = engine&.to_s + @engine = engine&.to_s || "ruby" @engine_versions = (engine_version && Array(engine_version)) || @versions @engine_gem_version = Gem::Requirement.create(@engine_versions.first).requirements.first.last @patchlevel = patchlevel || (@gem_version.prerelease? ? "-1" : nil) diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 72016e848baeb5..d8b7886af76448 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -247,7 +247,7 @@ def replace_gem(specs, specs_by_name) kernel = (class << ::Kernel; self; end) [kernel, ::Kernel].each do |kernel_class| redefine_method(kernel_class, :gem) do |dep, *reqs| - if executables && executables.include?(File.basename(caller.first.split(":").first)) + if executables&.include?(File.basename(caller.first.split(":").first)) break end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 4a9f3731bd1f56..adbce5fce4962c 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -67,6 +67,13 @@ def eql?(other) alias_method :==, :eql? + def include?(other) + other.is_a?(Git) && uri == other.uri && + name == other.name && + glob == other.glob && + submodules == other.submodules + end + def to_s begin at = humanized_ref || current_branch diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index 63798db941ed5d..4419695b7ff1ab 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -101,10 +101,6 @@ def get(source) source_list_for(source).find {|s| equivalent_source?(source, s) } end - def get_with_fallback(source) - get(source) || default_source - end - def lock_sources lock_other_sources + lock_rubygems_sources end diff --git a/lib/bundler/ui/rg_proxy.rb b/lib/bundler/ui/rg_proxy.rb index ef6def225b0862..b17ca65f53b61c 100644 --- a/lib/bundler/ui/rg_proxy.rb +++ b/lib/bundler/ui/rg_proxy.rb @@ -12,7 +12,7 @@ def initialize(ui) end def say(message) - @ui && @ui.debug(message) + @ui&.debug(message) end end end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index d070915000218a..8ef7be935b0531 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.4.18".freeze + VERSION = "2.4.19".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 3b4e4604ebb8df..af86646a82047f 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -9,7 +9,7 @@ require "rbconfig" module Gem - VERSION = "3.4.18" + VERSION = "3.4.19" end # Must be first since it unloads the prelude from 1.9.2 @@ -856,8 +856,7 @@ def self.latest_rubygems_version # Returns the version of the latest release-version of gem +name+ def self.latest_version_for(name) - spec = latest_spec_for name - spec && spec.version + latest_spec_for(name)&.version end ## diff --git a/lib/rubygems/bundler_version_finder.rb b/lib/rubygems/bundler_version_finder.rb index 2cbc4ff6242141..5b34227d3a2025 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -47,7 +47,7 @@ def self.lockfile_version def self.lockfile_contents gemfile = ENV["BUNDLE_GEMFILE"] - gemfile = nil if gemfile && gemfile.empty? + gemfile = nil if gemfile&.empty? unless gemfile begin diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index c59dd4d83f6743..92739617f67b50 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -73,8 +73,7 @@ def host @host ||= begin env_rubygems_host = ENV["RUBYGEMS_HOST"] - env_rubygems_host = nil if - env_rubygems_host && env_rubygems_host.empty? + env_rubygems_host = nil if env_rubygems_host&.empty? env_rubygems_host || configured_host end diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index f6ea6964db2170..f28d521bdfe0ee 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -617,8 +617,7 @@ def verify verify_checksums @digests, @checksums - @security_policy.verify_signatures @spec, @digests, @signatures if - @security_policy + @security_policy&.verify_signatures @spec, @digests, @signatures true rescue Gem::Security::Exception diff --git a/lib/rubygems/request_set/lockfile/parser.rb b/lib/rubygems/request_set/lockfile/parser.rb index 5bebfa60609159..1daec1fabd8c6b 100644 --- a/lib/rubygems/request_set/lockfile/parser.rb +++ b/lib/rubygems/request_set/lockfile/parser.rb @@ -332,7 +332,7 @@ def pinned_requirement(name) # :nodoc: set.find_all(requirement) end.compact.first - specification && specification.version + specification&.version end ## diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index ffc4f858a78dc4..7611e1ba1f4062 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1048,7 +1048,7 @@ def self.find_inactive_by_path(path) next if s.activated? s.contains_requirable_file? path end - stub && stub.to_spec + stub&.to_spec end def self.find_active_stub_by_path(path) @@ -1642,7 +1642,7 @@ def build_extensions # :nodoc: builder.build_extensions end ensure - ui.close if ui + ui&.close Gem::Specification.unresolved_deps.replace unresolved_deps end end diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 710bcf86f63306..451dba070f2bf3 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -292,7 +292,7 @@ def ask(question) @outs.flush result = @ins.gets - result.chomp! if result + result&.chomp! result end @@ -307,7 +307,7 @@ def ask_for_password(question) password = _gets_noecho @outs.puts - password.chomp! if password + password&.chomp! password end diff --git a/spec/bundler/bundler/fetcher/downloader_spec.rb b/spec/bundler/bundler/fetcher/downloader_spec.rb index 0412ddb83a3a54..22aa3a8b0c6809 100644 --- a/spec/bundler/bundler/fetcher/downloader_spec.rb +++ b/spec/bundler/bundler/fetcher/downloader_spec.rb @@ -98,6 +98,16 @@ end end + context "when the request response is a Net::HTTPForbidden" do + let(:http_response) { Net::HTTPForbidden.new("1.1", 403, "Forbidden") } + let(:uri) { Bundler::URI("http://user:password@www.uri-to-fetch.com") } + + it "should raise a Bundler::Fetcher::AuthenticationForbiddenError with the uri host" do + expect { subject.fetch(uri, options, counter) }.to raise_error(Bundler::Fetcher::AuthenticationForbiddenError, + /Access token could not be authenticated for www.uri-to-fetch.com/) + end + end + context "when the request response is a Net::HTTPNotFound" do let(:http_response) { Net::HTTPNotFound.new("1.1", 404, "Not Found") } diff --git a/spec/bundler/bundler/fetcher/index_spec.rb b/spec/bundler/bundler/fetcher/index_spec.rb index f0db07583cb4ab..971b64ce8f5538 100644 --- a/spec/bundler/bundler/fetcher/index_spec.rb +++ b/spec/bundler/bundler/fetcher/index_spec.rb @@ -63,26 +63,9 @@ context "when a 403 response occurs" do let(:error_message) { "403" } - before do - allow(remote_uri).to receive(:userinfo).and_return(userinfo) - end - - context "and there was userinfo" do - let(:userinfo) { double(:userinfo) } - - it "should raise a Bundler::Fetcher::BadAuthenticationError" do - expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::BadAuthenticationError, - %r{Bad username or password for http://remote-uri.org}) - end - end - - context "and there was no userinfo" do - let(:userinfo) { nil } - - it "should raise a Bundler::Fetcher::AuthenticationRequiredError" do - expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError, - %r{Authentication is required for http://remote-uri.org}) - end + it "should raise a Bundler::Fetcher::AuthenticationForbiddenError" do + expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationForbiddenError, + %r{Access token could not be authenticated for http://remote-uri.org}) end end diff --git a/spec/bundler/bundler/ruby_dsl_spec.rb b/spec/bundler/bundler/ruby_dsl_spec.rb index bc1ca98457b77a..0ba55e949f7c3d 100644 --- a/spec/bundler/bundler/ruby_dsl_spec.rb +++ b/spec/bundler/bundler/ruby_dsl_spec.rb @@ -11,6 +11,7 @@ class MockDSL let(:dsl) { MockDSL.new } let(:ruby_version) { "2.0.0" } + let(:ruby_version_arg) { ruby_version } let(:version) { "2.0.0" } let(:engine) { "jruby" } let(:engine_version) { "9000" } @@ -23,7 +24,10 @@ class MockDSL let(:invoke) do proc do - args = Array(ruby_version) + [options] + args = [] + args << Array(ruby_version_arg) if ruby_version_arg + args << options + dsl.ruby(*args) end end @@ -91,5 +95,26 @@ class MockDSL it_behaves_like "it stores the ruby version" end end + + context "with a file option" do + let(:options) { { :file => "foo" } } + let(:version) { "3.2.2" } + let(:ruby_version) { "3.2.2" } + let(:ruby_version_arg) { nil } + let(:engine_version) { version } + let(:patchlevel) { nil } + let(:engine) { "ruby" } + before { allow(Bundler).to receive(:read_file).with("foo").and_return("#{version}\n") } + + it_behaves_like "it stores the ruby version" + + context "and a version" do + let(:ruby_version_arg) { "2.0.0" } + + it "raises an error" do + expect { subject }.to raise_error(Bundler::GemfileError, "Cannot specify version when using the file option") + end + end + end end end diff --git a/spec/bundler/install/gems/compact_index_spec.rb b/spec/bundler/install/gems/compact_index_spec.rb index 8ab8e61673cbb0..65be2627487098 100644 --- a/spec/bundler/install/gems/compact_index_spec.rb +++ b/spec/bundler/install/gems/compact_index_spec.rb @@ -683,6 +683,15 @@ def require(*args) bundle :install, :artifice => "compact_index_strict_basic_authentication", :raise_on_error => false expect(err).to include("Bad username or password") end + + it "does not fallback to old dependency API if bad authentication is provided" do + bundle "config set #{source_hostname} #{user}:wrong" + + bundle :install, :artifice => "compact_index_strict_basic_authentication", :raise_on_error => false, :verbose => true + expect(err).to include("Bad username or password") + expect(out).to include("HTTP 401 Unauthorized http://user@localgemserver.test/versions") + expect(out).not_to include("HTTP 401 Unauthorized http://user@localgemserver.test/api/v1/dependencies") + end end describe "with no password" do diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb index 4b78cb261d2556..ccf23a9e3c2144 100644 --- a/spec/bundler/lock/lockfile_spec.rb +++ b/spec/bundler/lock/lockfile_spec.rb @@ -540,6 +540,92 @@ G end + it "is conservative with dependencies of git gems" do + build_repo4 do + build_gem "orm_adapter", "0.4.1" + build_gem "orm_adapter", "0.5.0" + end + + FileUtils.mkdir_p lib_path("ckeditor/lib") + + @remote = build_git("ckeditor_remote", :bare => true) + + build_git "ckeditor", :path => lib_path("ckeditor") do |s| + s.write "lib/ckeditor.rb", "CKEDITOR = '4.0.7'" + s.version = "4.0.7" + s.add_dependency "orm_adapter" + end + + update_git "ckeditor", :path => lib_path("ckeditor"), :remote => file_uri_for(@remote.path) + update_git "ckeditor", :path => lib_path("ckeditor"), :tag => "v4.0.7" + old_git = update_git "ckeditor", :path => lib_path("ckeditor"), :push => "v4.0.7" + + update_git "ckeditor", :path => lib_path("ckeditor"), :gemspec => true do |s| + s.write "lib/ckeditor.rb", "CKEDITOR = '4.0.8'" + s.version = "4.0.8" + s.add_dependency "orm_adapter" + end + update_git "ckeditor", :path => lib_path("ckeditor"), :tag => "v4.0.8" + + new_git = update_git "ckeditor", :path => lib_path("ckeditor"), :push => "v4.0.8" + + gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem "ckeditor", :git => "#{@remote.path}", :tag => "v4.0.8" + G + + lockfile <<~L + GIT + remote: #{@remote.path} + revision: #{old_git.ref_for("v4.0.7")} + tag: v4.0.7 + specs: + ckeditor (4.0.7) + orm_adapter + + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + orm_adapter (0.4.1) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + ckeditor! + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "lock" + + # Bumps the git gem, but keeps its dependency locked + expect(lockfile).to eq <<~L + GIT + remote: #{@remote.path} + revision: #{new_git.ref_for("v4.0.8")} + tag: v4.0.8 + specs: + ckeditor (4.0.8) + orm_adapter + + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + orm_adapter (0.4.1) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + ckeditor! + + BUNDLED WITH + #{Bundler::VERSION} + L + end + it "serializes pinned path sources to the lockfile" do build_lib "foo" diff --git a/spec/bundler/support/artifice/compact_index_strict_basic_authentication.rb b/spec/bundler/support/artifice/compact_index_strict_basic_authentication.rb index fa25c4eca1492b..96259385e77c54 100644 --- a/spec/bundler/support/artifice/compact_index_strict_basic_authentication.rb +++ b/spec/bundler/support/artifice/compact_index_strict_basic_authentication.rb @@ -10,7 +10,7 @@ class CompactIndexStrictBasicAuthentication < CompactIndexAPI # Only accepts password == "password" unless env["HTTP_AUTHORIZATION"] == "Basic dXNlcjpwYXNz" - halt 403, "Authentication failed" + halt 401, "Authentication failed" end end end diff --git a/spec/bundler/support/artifice/endpoint_strict_basic_authentication.rb b/spec/bundler/support/artifice/endpoint_strict_basic_authentication.rb index 8ce1bdd4adf028..dff360c5c535c2 100644 --- a/spec/bundler/support/artifice/endpoint_strict_basic_authentication.rb +++ b/spec/bundler/support/artifice/endpoint_strict_basic_authentication.rb @@ -10,7 +10,7 @@ class EndpointStrictBasicAuthentication < Endpoint # Only accepts password == "password" unless env["HTTP_AUTHORIZATION"] == "Basic dXNlcjpwYXNz" - halt 403, "Authentication failed" + halt 401, "Authentication failed" end end end diff --git a/spec/bundler/support/artifice/vcr.rb b/spec/bundler/support/artifice/vcr.rb index 25bfd1426f4fb6..6a346f1ff96553 100644 --- a/spec/bundler/support/artifice/vcr.rb +++ b/spec/bundler/support/artifice/vcr.rb @@ -47,7 +47,7 @@ def recorded_response response.uri = request.uri response.reading_body(response_io, request.response_body_permitted?) do - response_block.call(response) if response_block + response_block&.call(response) end end end diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index 747fd92d0d6993..688d121599bd36 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -1625,7 +1625,7 @@ def stub(name, val_or_callable, *block_args) if val_or_callable.respond_to? :call val_or_callable.call(*args, &blk) else - blk.call(*block_args) if blk + blk&.call(*block_args) val_or_callable end end