summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2021-01-14 13:38:17 +0900
committerNARUSE, Yui <nurse@users.noreply.github.com>2021-01-14 16:44:42 +0900
commit93dcf0828dc8e627e0c24497795d927911a9d993 (patch)
tree391f87ebf731d82c74fc44322a012024c3bd62f7
parentc721e36ceca587d823a765cbbad90911a20cffce (diff)
Merge Bundler-2.2.5
-rw-r--r--lib/bundler.rb1
-rw-r--r--lib/bundler/cli/gem.rb2
-rw-r--r--lib/bundler/compact_index_client/updater.rb8
-rw-r--r--lib/bundler/gem_helper.rb6
-rw-r--r--lib/bundler/resolver.rb7
-rw-r--r--lib/bundler/source/git.rb34
-rw-r--r--lib/bundler/source/git/git_proxy.rb52
-rw-r--r--lib/bundler/source/path/installer.rb2
-rw-r--r--lib/bundler/source/rubygems.rb11
-rw-r--r--lib/bundler/templates/newgem/Gemfile.tt2
-rw-r--r--lib/bundler/templates/newgem/newgem.gemspec.tt2
-rw-r--r--lib/bundler/templates/newgem/rubocop.yml.tt3
-rw-r--r--lib/bundler/version.rb2
-rw-r--r--spec/bundler/bundler/compact_index_client/updater_spec.rb4
-rw-r--r--spec/bundler/bundler/gem_helper_spec.rb10
-rw-r--r--spec/bundler/bundler/source/git/git_proxy_spec.rb8
-rw-r--r--spec/bundler/bundler/source/git_spec.rb4
-rw-r--r--spec/bundler/commands/install_spec.rb29
-rw-r--r--spec/bundler/commands/newgem_spec.rb8
-rw-r--r--spec/bundler/install/deploy_spec.rb6
-rw-r--r--spec/bundler/install/gems/resolving_spec.rb17
-rw-r--r--spec/bundler/install/git_spec.rb21
-rw-r--r--spec/bundler/lock/lockfile_spec.rb2
-rw-r--r--spec/bundler/realworld/edgecases_spec.rb30
-rw-r--r--spec/bundler/runtime/setup_spec.rb79
-rw-r--r--spec/bundler/support/builders.rb2
26 files changed, 240 insertions, 112 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index c72ad27c40..b299cc8a28 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -63,7 +63,6 @@ module Bundler
autoload :Resolver, File.expand_path("bundler/resolver", __dir__)
autoload :Retry, File.expand_path("bundler/retry", __dir__)
autoload :RubyDsl, File.expand_path("bundler/ruby_dsl", __dir__)
- autoload :RubyGemsGemInstaller, File.expand_path("bundler/rubygems_gem_installer", __dir__)
autoload :RubyVersion, File.expand_path("bundler/ruby_version", __dir__)
autoload :Runtime, File.expand_path("bundler/runtime", __dir__)
autoload :Settings, File.expand_path("bundler/settings", __dir__)
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index 8d26e4c1f4..17b4956fa0 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -59,6 +59,7 @@ module Bundler
:exe => options[:exe],
:bundler_version => bundler_dependency_version,
:github_username => github_username.empty? ? "[USERNAME]" : github_username,
+ :required_ruby_version => Gem.ruby_version < Gem::Version.new("2.4.a") ? "2.3.0" : "2.4.0",
}
ensure_safe_gem_name(name, constant_array)
@@ -147,6 +148,7 @@ module Bundler
"For more information, see the RuboCop docs (https://docs.rubocop.org/en/stable/) " \
"and the Ruby Style Guides (https://github.com/rubocop-hq/ruby-style-guide).")
config[:rubocop] = true
+ config[:rubocop_version] = Gem.ruby_version < Gem::Version.new("2.4.a") ? "0.81.0" : "1.7"
Bundler.ui.info "RuboCop enabled in config"
templates.merge!("rubocop.yml.tt" => ".rubocop.yml")
end
diff --git a/lib/bundler/compact_index_client/updater.rb b/lib/bundler/compact_index_client/updater.rb
index 66d1735583..7959e5c089 100644
--- a/lib/bundler/compact_index_client/updater.rb
+++ b/lib/bundler/compact_index_client/updater.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true
require_relative "../vendored_fileutils"
-require "stringio"
-require "zlib"
module Bundler
class CompactIndexClient
@@ -45,18 +43,12 @@ module Bundler
else
"bytes=#{local_temp_path.size}-"
end
- else
- # Fastly ignores Range when Accept-Encoding: gzip is set
- headers["Accept-Encoding"] = "gzip"
end
response = @fetcher.call(remote_path, headers)
return nil if response.is_a?(Net::HTTPNotModified)
content = response.body
- if response["Content-Encoding"] == "gzip"
- content = Zlib::GzipReader.new(StringIO.new(content)).read
- end
SharedHelpers.filesystem_access(local_temp_path) do
if response.is_a?(Net::HTTPPartialContent) && local_temp_path.size.nonzero?
diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb
index 4ada36aef4..0acaa69f25 100644
--- a/lib/bundler/gem_helper.rb
+++ b/lib/bundler/gem_helper.rb
@@ -117,13 +117,13 @@ module Bundler
def git_push(remote = nil)
remote ||= default_remote
perform_git_push remote
- perform_git_push "#{remote} #{version_tag}"
+ perform_git_push "#{remote} refs/tags/#{version_tag}"
Bundler.ui.confirm "Pushed git commits and release tag."
end
def default_remote
- current_branch = sh(%w[git rev-parse --abbrev-ref HEAD]).strip
- return "origin" if current_branch.empty?
+ # We can replace this with `git branch --show-current` once we drop support for git < 2.22.0
+ current_branch = sh(%w[git rev-parse --abbrev-ref HEAD]).gsub(%r{\Aheads/}, "").strip
remote_for_branch = sh(%W[git config --get branch.#{current_branch}.remote]).strip
return "origin" if remote_for_branch.empty?
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 636dc8af46..4972d85e08 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -163,7 +163,12 @@ module Bundler
# Add a spec group for "non platform specific spec" as the fallback
# spec group.
sg_ruby = sg.copy_for([Gem::Platform::RUBY])
- selected_sgs.insert(-2, sg_ruby) if sg_ruby
+ next unless sg_ruby
+
+ sg_ruby_deps = sg_ruby.dependencies_for_activated_platforms.map(&:dep)
+ sg_all_platforms_deps = sg_all_platforms.dependencies_for_activated_platforms.map(&:dep)
+
+ selected_sgs.insert(-2, sg_ruby) if sg_ruby_deps != sg_all_platforms_deps
end
selected_sgs
end
diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb
index 0157995cb0..a3e6439d5d 100644
--- a/lib/bundler/source/git.rb
+++ b/lib/bundler/source/git.rb
@@ -22,7 +22,7 @@ module Bundler
@uri = options["uri"] || ""
@safe_uri = URICredentialsFilter.credential_filtered_uri(@uri)
@branch = options["branch"]
- @ref = options["ref"] || options["branch"] || options["tag"] || "master"
+ @ref = options["ref"] || options["branch"] || options["tag"]
@submodules = options["submodules"]
@name = options["name"]
@version = options["version"].to_s.strip.gsub("-", ".pre.")
@@ -60,25 +60,27 @@ module Bundler
alias_method :==, :eql?
def to_s
- at = if local?
- path
- elsif user_ref = options["ref"]
- if ref =~ /\A[a-z0-9]{4,}\z/i
- shortref_for_display(user_ref)
+ begin
+ at = if local?
+ path
+ elsif user_ref = options["ref"]
+ if ref =~ /\A[a-z0-9]{4,}\z/i
+ shortref_for_display(user_ref)
+ else
+ user_ref
+ end
+ elsif ref
+ ref
else
- user_ref
+ git_proxy.branch
end
- else
- ref
- end
- rev = begin
- "@#{shortref_for_display(revision)}"
- rescue GitError
- nil
- end
+ rev = " (at #{at}@#{shortref_for_display(revision)})"
+ rescue GitError
+ ""
+ end
- "#{@safe_uri} (at #{at}#{rev})"
+ "#{@safe_uri}#{rev}"
end
def name
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb
index dd65c674d8..ae21770306 100644
--- a/lib/bundler/source/git/git_proxy.rb
+++ b/lib/bundler/source/git/git_proxy.rb
@@ -17,7 +17,7 @@ module Bundler
class GitNotAllowedError < GitError
def initialize(command)
msg = String.new
- msg << "Bundler is trying to run a `git #{command}` at runtime. You probably need to run `bundle install`. However, "
+ msg << "Bundler is trying to run `#{command}` at runtime. You probably need to run `bundle install`. However, "
msg << "this error message could probably be more useful. Please submit a ticket at https://github.com/rubygems/rubygems/issues/new?labels=Bundler&template=bundler-related-issue.md "
msg << "with steps to reproduce as well as the following\n\nCALLER: #{caller.join("\n")}"
super msg
@@ -27,11 +27,11 @@ module Bundler
class GitCommandError < GitError
attr_reader :command
- def initialize(command, path, destination_path, extra_info = nil)
+ def initialize(command, path, extra_info = nil)
@command = command
msg = String.new
- msg << "Git error: command `git #{command}` in directory #{destination_path} has failed."
+ msg << "Git error: command `#{command}` in directory #{path} has failed."
msg << "\n#{extra_info}" if extra_info
msg << "\nIf this error persists you could try removing the cache directory '#{path}'" if path.exist?
super msg
@@ -39,9 +39,9 @@ module Bundler
end
class MissingGitRevisionError < GitCommandError
- def initialize(command, path, destination_path, ref, repo)
+ def initialize(command, destination_path, ref, repo)
msg = "Revision #{ref} does not exist in the repository #{repo}. Maybe you misspelled it?"
- super command, path, destination_path, msg
+ super command, destination_path, msg
end
end
@@ -132,7 +132,7 @@ module Bundler
begin
git "reset", "--hard", @revision, :dir => destination
rescue GitCommandError => e
- raise MissingGitRevisionError.new(e.command, path, destination, @revision, URICredentialsFilter.credential_filtered_uri(uri))
+ raise MissingGitRevisionError.new(e.command, destination, @revision, URICredentialsFilter.credential_filtered_uri(uri))
end
if submodules
@@ -145,32 +145,36 @@ module Bundler
private
- def git_null(*command, dir: SharedHelpers.pwd)
+ def git_null(*command, dir: nil)
check_allowed(command)
out, status = SharedHelpers.with_clean_git_env do
- capture_and_ignore_stderr("git", "-C", dir.to_s, *command)
+ capture_and_ignore_stderr(*capture3_args_for(command, dir))
end
[URICredentialsFilter.credential_filtered_string(out, uri), status]
end
- def git_retry(*command, dir: SharedHelpers.pwd)
- Bundler::Retry.new("`git -C #{dir} #{URICredentialsFilter.credential_filtered_string(command.shelljoin, uri)}`", GitNotAllowedError).attempts do
+ def git_retry(*command, dir: nil)
+ command_with_no_credentials = check_allowed(command)
+
+ Bundler::Retry.new("`#{command_with_no_credentials}` at #{dir || SharedHelpers.pwd}").attempts do
git(*command, :dir => dir)
end
end
- def git(*command, dir: SharedHelpers.pwd)
+ def git(*command, dir: nil)
command_with_no_credentials = check_allowed(command)
out, status = SharedHelpers.with_clean_git_env do
- capture_and_filter_stderr("git", "-C", dir.to_s, *command)
+ capture_and_filter_stderr(*capture3_args_for(command, dir))
end
- raise GitCommandError.new(command_with_no_credentials, path, dir) unless status.success?
+ filtered_out = URICredentialsFilter.credential_filtered_string(out, uri)
+
+ raise GitCommandError.new(command_with_no_credentials, dir || SharedHelpers.pwd, filtered_out) unless status.success?
- URICredentialsFilter.credential_filtered_string(out, uri)
+ filtered_out
end
def has_revision_cached?
@@ -187,10 +191,10 @@ module Bundler
def find_local_revision
allowed_with_path do
- git("rev-parse", "--verify", ref, :dir => path).strip
+ git("rev-parse", "--verify", ref || "HEAD", :dir => path).strip
end
rescue GitCommandError => e
- raise MissingGitRevisionError.new(e.command, path, path, ref, URICredentialsFilter.credential_filtered_uri(uri))
+ raise MissingGitRevisionError.new(e.command, path, ref, URICredentialsFilter.credential_filtered_uri(uri))
end
# Adds credentials to the URI as Fetcher#configured_uri_for does
@@ -220,7 +224,7 @@ module Bundler
end
def check_allowed(command)
- command_with_no_credentials = URICredentialsFilter.credential_filtered_string(command.shelljoin, uri)
+ command_with_no_credentials = URICredentialsFilter.credential_filtered_string("git #{command.shelljoin}", uri)
raise GitNotAllowedError.new(command_with_no_credentials) unless allow?
command_with_no_credentials
end
@@ -237,6 +241,20 @@ module Bundler
return_value, _, status = Open3.capture3(*cmd)
[return_value, status]
end
+
+ def capture3_args_for(cmd, dir)
+ return ["git", *cmd] unless dir
+
+ if Bundler.feature_flag.bundler_3_mode? || supports_minus_c?
+ ["git", "-C", dir.to_s, *cmd]
+ else
+ ["git", *cmd, { :chdir => dir.to_s }]
+ end
+ end
+
+ def supports_minus_c?
+ @supports_minus_c ||= Gem::Version.new(version) >= Gem::Version.new("1.8.5")
+ end
end
end
end
diff --git a/lib/bundler/source/path/installer.rb b/lib/bundler/source/path/installer.rb
index 6be58e2087..72bfbb4836 100644
--- a/lib/bundler/source/path/installer.rb
+++ b/lib/bundler/source/path/installer.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require_relative "../../rubygems_gem_installer"
+
module Bundler
class Source
class Path
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb
index 97f9808578..a6ac5613d0 100644
--- a/lib/bundler/source/rubygems.rb
+++ b/lib/bundler/source/rubygems.rb
@@ -145,6 +145,8 @@ module Bundler
Bundler.mkdir_p bin_path, :no_sudo => true unless spec.executables.empty? || Bundler.rubygems.provides?(">= 2.7.5")
+ require_relative "../rubygems_gem_installer"
+
installed_spec = Bundler::RubyGemsGemInstaller.at(
path,
:install_dir => install_path.to_s,
@@ -487,8 +489,15 @@ module Bundler
uri = spec.remote.uri
Bundler.ui.confirm("Fetching #{version_message(spec)}")
rubygems_local_path = Bundler.rubygems.download_gem(spec, uri, download_path)
+
+ # older rubygems return varying file:// variants depending on version
+ rubygems_local_path = rubygems_local_path.gsub(/\Afile:/, "") unless Bundler.rubygems.provides?(">= 3.2.0.rc.2")
+ rubygems_local_path = rubygems_local_path.gsub(%r{\A//}, "") if Bundler.rubygems.provides?("< 3.1.0")
+
if rubygems_local_path != local_path
- FileUtils.mv(rubygems_local_path, local_path)
+ SharedHelpers.filesystem_access(local_path) do
+ FileUtils.mv(rubygems_local_path, local_path)
+ end
end
cache_globally(spec, local_path)
end
diff --git a/lib/bundler/templates/newgem/Gemfile.tt b/lib/bundler/templates/newgem/Gemfile.tt
index 1d55fd7a90..b09ccfff15 100644
--- a/lib/bundler/templates/newgem/Gemfile.tt
+++ b/lib/bundler/templates/newgem/Gemfile.tt
@@ -16,5 +16,5 @@ gem "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>"
<%- end -%>
<%- if config[:rubocop] -%>
-gem "rubocop", "~> 0.80"
+gem "rubocop", "~> <%= config[:rubocop_version] %>"
<%- end -%>
diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt
index 97c3b6c5ab..632b24dda9 100644
--- a/lib/bundler/templates/newgem/newgem.gemspec.tt
+++ b/lib/bundler/templates/newgem/newgem.gemspec.tt
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
<%- if config[:mit] -%>
spec.license = "MIT"
<%- end -%>
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
+ spec.required_ruby_version = Gem::Requirement.new(">= <%= config[:required_ruby_version] %>")
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
diff --git a/lib/bundler/templates/newgem/rubocop.yml.tt b/lib/bundler/templates/newgem/rubocop.yml.tt
index 00a72e3006..9ecec78807 100644
--- a/lib/bundler/templates/newgem/rubocop.yml.tt
+++ b/lib/bundler/templates/newgem/rubocop.yml.tt
@@ -1,3 +1,6 @@
+AllCops:
+ TargetRubyVersion: <%= ::Gem::Version.new(config[:required_ruby_version]).segments[0..1].join(".") %>
+
Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb
index 531a21988a..5a49ea546e 100644
--- a/lib/bundler/version.rb
+++ b/lib/bundler/version.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
module Bundler
- VERSION = "2.2.4".freeze
+ VERSION = "2.2.5".freeze
def self.bundler_major_version
@bundler_major_version ||= VERSION.split(".").first.to_i
diff --git a/spec/bundler/bundler/compact_index_client/updater_spec.rb b/spec/bundler/bundler/compact_index_client/updater_spec.rb
index acb312edb3..d8bb15df7e 100644
--- a/spec/bundler/bundler/compact_index_client/updater_spec.rb
+++ b/spec/bundler/bundler/compact_index_client/updater_spec.rb
@@ -17,7 +17,6 @@ RSpec.describe Bundler::CompactIndexClient::Updater do
let(:response) { double(:response, :body => "abc123") }
it "treats the response as an update" do
- expect(response).to receive(:[]).with("Content-Encoding") { "" }
expect(response).to receive(:[]).with("ETag") { nil }
expect(fetcher).to receive(:call) { response }
@@ -29,8 +28,7 @@ RSpec.describe Bundler::CompactIndexClient::Updater do
let(:response) { double(:response, :body => "") }
it "raises HTTPError" do
- expect(response).to receive(:[]).with("Content-Encoding") { "gzip" }
- expect(fetcher).to receive(:call) { response }
+ expect(fetcher).to receive(:call).and_raise(Zlib::GzipFile::Error)
expect do
updater.update(local_path, remote_path)
diff --git a/spec/bundler/bundler/gem_helper_spec.rb b/spec/bundler/bundler/gem_helper_spec.rb
index 48af7867b4..30befdf40c 100644
--- a/spec/bundler/bundler/gem_helper_spec.rb
+++ b/spec/bundler/bundler/gem_helper_spec.rb
@@ -256,6 +256,16 @@ RSpec.describe Bundler::GemHelper do
Rake.application["release"].invoke
end
+
+ it "also works when releasing from an ambiguous reference" do
+ # Create a branch with the same name as the tag
+ sys_exec("git checkout -b v#{app_version}", :dir => app_path)
+ sys_exec("git push -u origin v#{app_version}", :dir => app_path)
+
+ expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s)
+
+ Rake.application["release"].invoke
+ end
end
context "on releasing with a custom tag prefix" do
diff --git a/spec/bundler/bundler/source/git/git_proxy_spec.rb b/spec/bundler/bundler/source/git/git_proxy_spec.rb
index 35702d7763..97f06973cb 100644
--- a/spec/bundler/bundler/source/git/git_proxy_spec.rb
+++ b/spec/bundler/bundler/source/git/git_proxy_spec.rb
@@ -130,18 +130,20 @@ RSpec.describe Bundler::Source::Git::GitProxy do
context "when given a SHA as a revision" do
let(:revision) { "abcd" * 10 }
let(:command) { ["reset", "--hard", revision] }
+ let(:command_for_display) { "git #{command.shelljoin}" }
it "fails gracefully when resetting to the revision fails" do
expect(subject).to receive(:git_retry).with("clone", any_args) { destination.mkpath }
expect(subject).to receive(:git_retry).with("fetch", any_args, :dir => destination)
- expect(subject).to receive(:git).with(*command, :dir => destination).and_raise(Bundler::Source::Git::GitCommandError.new(command, cache, destination))
+ expect(subject).to receive(:git).with(*command, :dir => destination).and_raise(Bundler::Source::Git::GitCommandError.new(command_for_display, destination))
expect(subject).not_to receive(:git)
expect { subject.copy_to(destination, submodules) }.
to raise_error(
Bundler::Source::Git::MissingGitRevisionError,
- "Git error: command `git #{command}` in directory #{destination} has failed.\n" \
- "Revision #{revision} does not exist in the repository #{uri}. Maybe you misspelled it?" \
+ "Git error: command `#{command_for_display}` in directory #{destination} has failed.\n" \
+ "Revision #{revision} does not exist in the repository #{uri}. Maybe you misspelled it?\n" \
+ "If this error persists you could try removing the cache directory '#{destination}'"
)
end
end
diff --git a/spec/bundler/bundler/source/git_spec.rb b/spec/bundler/bundler/source/git_spec.rb
index f7475a35aa..6668b6e69a 100644
--- a/spec/bundler/bundler/source/git_spec.rb
+++ b/spec/bundler/bundler/source/git_spec.rb
@@ -14,14 +14,14 @@ RSpec.describe Bundler::Source::Git do
describe "#to_s" do
it "returns a description" do
- expect(subject.to_s).to eq "https://github.com/foo/bar.git (at master)"
+ expect(subject.to_s).to eq "https://github.com/foo/bar.git"
end
context "when the URI contains credentials" do
let(:uri) { "https://my-secret-token:x-oauth-basic@github.com/foo/bar.git" }
it "filters credentials" do
- expect(subject.to_s).to eq "https://x-oauth-basic@github.com/foo/bar.git (at master)"
+ expect(subject.to_s).to eq "https://x-oauth-basic@github.com/foo/bar.git"
end
end
end
diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb
index 043805df79..f12d32d6a8 100644
--- a/spec/bundler/commands/install_spec.rb
+++ b/spec/bundler/commands/install_spec.rb
@@ -580,8 +580,31 @@ RSpec.describe "bundle install with gem sources" do
end
describe "when bundle path does not have write access", :permissions do
+ let(:bundle_path) { bundled_app("vendor") }
+
+ before do
+ FileUtils.mkdir_p(bundle_path)
+ gemfile <<-G
+ source "#{file_uri_for(gem_repo1)}"
+ gem 'rack'
+ G
+ end
+
+ it "should display a proper message to explain the problem" do
+ FileUtils.chmod(0o500, bundle_path)
+
+ bundle "config set --local path vendor"
+ bundle :install, :raise_on_error => false
+ expect(err).to include(bundle_path.to_s)
+ expect(err).to include("grant write permissions")
+ end
+ end
+
+ describe "when bundle cache path does not have write access", :permissions do
+ let(:cache_path) { bundled_app("vendor/#{Bundler.ruby_scope}/cache") }
+
before do
- FileUtils.mkdir_p(bundled_app("vendor"))
+ FileUtils.mkdir_p(cache_path)
gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem 'rack'
@@ -589,11 +612,11 @@ RSpec.describe "bundle install with gem sources" do
end
it "should display a proper message to explain the problem" do
- FileUtils.chmod(0o500, bundled_app("vendor"))
+ FileUtils.chmod(0o500, cache_path)
bundle "config --local path vendor"
bundle :install, :raise_on_error => false
- expect(err).to include(bundled_app("vendor").to_s)
+ expect(err).to include(cache_path.to_s)
expect(err).to include("grant write permissions")
end
end
diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb
index 421ffa80c6..265268a1fe 100644
--- a/spec/bundler/commands/newgem_spec.rb
+++ b/spec/bundler/commands/newgem_spec.rb
@@ -12,10 +12,10 @@ RSpec.describe "bundle gem" do
def bundle_exec_rubocop
prepare_gemspec(bundled_app(gem_name, "#{gem_name}.gemspec"))
- rubocop_version = RUBY_VERSION > "2.4" ? "0.90.0" : "0.80.1"
+ rubocop_version = RUBY_VERSION > "2.4" ? "1.7.0" : "0.81.0"
gems = ["minitest", "rake", "rake-compiler", "rspec", "rubocop -v #{rubocop_version}", "test-unit"]
gems.unshift "parallel -v 1.19.2" if RUBY_VERSION < "2.5"
- gems += ["rubocop-ast -v 0.4.0"] if rubocop_version == "0.90.0"
+ gems += ["rubocop-ast -v 1.4.0"] if rubocop_version == "1.7.0"
path = Bundler.feature_flag.default_install_uses_path? ? local_gem_path(:base => bundled_app(gem_name)) : system_gem_path
realworld_system_gems gems, :path => path
bundle "exec rubocop --debug --config .rubocop.yml", :dir => bundled_app(gem_name)
@@ -416,9 +416,7 @@ RSpec.describe "bundle gem" do
it "sets a minimum ruby version" do
bundle "gem #{gem_name}"
- bundler_gemspec = Bundler::GemHelper.new(gemspec_dir).gemspec
-
- expect(bundler_gemspec.required_ruby_version).to eq(generated_gemspec.required_ruby_version)
+ expect(generated_gemspec.required_ruby_version).to eq(Gem::Requirement.new(Gem.ruby_version < Gem::Version.new("2.4.a") ? ">= 2.3.0" : ">= 2.4.0"))
end
it "requires the version file" do
diff --git a/spec/bundler/install/deploy_spec.rb b/spec/bundler/install/deploy_spec.rb
index 357f4512f1..73a0c18f4a 100644
--- a/spec/bundler/install/deploy_spec.rb
+++ b/spec/bundler/install/deploy_spec.rb
@@ -341,7 +341,7 @@ RSpec.describe "install in deployment or frozen mode" do
bundle "config --local deployment true"
bundle :install, :raise_on_error => false
expect(err).to include("deployment mode")
- expect(err).to include("You have added to the Gemfile:\n* source: git://hubz.com (at master)")
+ expect(err).to include("You have added to the Gemfile:\n* source: git://hubz.com")
expect(err).not_to include("You have changed in the Gemfile")
end
@@ -361,7 +361,7 @@ RSpec.describe "install in deployment or frozen mode" do
bundle "config --local deployment true"
bundle :install, :raise_on_error => false
expect(err).to include("deployment mode")
- expect(err).to include("You have deleted from the Gemfile:\n* source: #{lib_path("rack-1.0")} (at master@#{revision_for(lib_path("rack-1.0"))[0..6]}")
+ expect(err).to include("You have deleted from the Gemfile:\n* source: #{lib_path("rack-1.0")}")
expect(err).not_to include("You have added to the Gemfile")
expect(err).not_to include("You have changed in the Gemfile")
end
@@ -385,7 +385,7 @@ RSpec.describe "install in deployment or frozen mode" do
bundle "config --local deployment true"
bundle :install, :raise_on_error => false
expect(err).to include("deployment mode")
- expect(err).to include("You have changed in the Gemfile:\n* rack from `no specified source` to `#{lib_path("rack")} (at master@#{revision_for(lib_path("rack"))[0..6]})`")
+ expect(err).to include("You have changed in the Gemfile:\n* rack from `no specified source` to `#{lib_path("rack")}`")
expect(err).not_to include("You have added to the Gemfile")
expect(err).not_to include("You have deleted from the Gemfile")
end
diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb
index 4384a731cd..d4cccbe051 100644
--- a/spec/bundler/install/gems/resolving_spec.rb
+++ b/spec/bundler/install/gems/resolving_spec.rb
@@ -142,10 +142,13 @@ RSpec.describe "bundle install with install-time dependencies" do
gem "net_e"
G
- bundle :install, :env => { "DEBUG_RESOLVER_TREE" => "1" }
+ bundle :install, :env => { "DEBUG_RESOLVER_TREE" => "1", "DEBUG" => "1" }
- activated_groups = "net_b (1.0) (ruby)"
- activated_groups += ", net_b (1.0) (#{local_platforms.join(", ")})" if local_platforms.any? && local_platforms != ["ruby"]
+ activated_groups = if local_platforms.any?
+ "net_b (1.0) (#{local_platforms.join(", ")})"
+ else
+ "net_b (1.0) (ruby)"
+ end
expect(out).to include(" net_b").
and include("BUNDLER: Starting resolution").
@@ -239,7 +242,7 @@ RSpec.describe "bundle install with install-time dependencies" do
let(:ruby_requirement) { %("#{RUBY_VERSION}") }
let(:error_message_requirement) { "~> #{RUBY_VERSION}.0" }
- let(:error_message_platform) { " #{Bundler.local_platform}" }
+ let(:error_message_platform) { Bundler.local_platform }
shared_examples_for "ruby version conflicts" do
it "raises an error during resolution" do
@@ -256,10 +259,10 @@ RSpec.describe "bundle install with install-time dependencies" do
nice_error = strip_whitespace(<<-E).strip
Bundler found conflicting requirements for the Ruby\0 version:
In Gemfile:
- Ruby\0 (#{error_message_requirement})#{error_message_platform}
+ Ruby\0 (#{error_message_requirement}) #{error_message_platform}
- require_ruby#{error_message_platform} was resolved to 1.0, which depends on
- Ruby\0 (> 9000)
+ require_ruby #{error_message_platform} was resolved to 1.0, which depends on
+ Ruby\0 (> 9000) #{error_message_platform}
Ruby\0 (> 9000), which is required by gem 'require_ruby', is not available in the local ruby installation
E
diff --git a/spec/bundler/install/git_spec.rb b/spec/bundler/install/git_spec.rb
index 62658137e0..61eaee4a84 100644
--- a/spec/bundler/install/git_spec.rb
+++ b/spec/bundler/install/git_spec.rb
@@ -2,10 +2,10 @@
RSpec.describe "bundle install" do
context "git sources" do
- it "displays the revision hash of the gem repository", :bundler => "< 3" do
+ it "displays the revision hash of the gem repository" do
build_git "foo", "1.0", :path => lib_path("foo")
- install_gemfile <<-G
+ install_gemfile <<-G, :verbose => true
gem "foo", :git => "#{file_uri_for(lib_path("foo"))}"
G
@@ -13,7 +13,18 @@ RSpec.describe "bundle install" do
expect(the_bundle).to include_gems "foo 1.0", :source => "git@#{lib_path("foo")}"
end
- it "displays the ref of the gem repository when using branch~num as a ref", :bundler => "< 3" do
+ it "displays the correct default branch" do
+ build_git "foo", "1.0", :path => lib_path("foo"), :default_branch => "main"
+
+ install_gemfile <<-G, :verbose => true
+ gem "foo", :git => "#{file_uri_for(lib_path("foo"))}"
+ G
+
+ expect(out).to include("Using foo 1.0 from #{file_uri_for(lib_path("foo"))} (at main@#{revision_for(lib_path("foo"))[0..6]})")
+ expect(the_bundle).to include_gems "foo 1.0", :source => "git@#{lib_path("foo")}"
+ end
+
+ it "displays the ref of the gem repository when using branch~num as a ref" do
skip "maybe branch~num notation doesn't work on Windows' git" if Gem.win_platform?
build_git "foo", "1.0", :path => lib_path("foo")
@@ -22,7 +33,7 @@ RSpec.describe "bundle install" do
rev2 = revision_for(lib_path("foo"))[0..6]
update_git "foo", "3.0", :path => lib_path("foo"), :gemspec => true
- install_gemfile <<-G
+ install_gemfile <<-G, :verbose => true
gem "foo", :git => "#{file_uri_for(lib_path("foo"))}", :ref => "master~2"
G
@@ -31,7 +42,7 @@ RSpec.describe "bundle install" do
update_git "foo", "4.0", :path => lib_path("foo"), :gemspec => true
- bundle :update, :all => true
+ bundle :update, :all => true, :verbose => true
expect(out).to include("Using foo 2.0 (was 1.0) from #{file_uri_for(lib_path("foo"))} (at master~2@#{rev2})")
expect(the_bundle).to include_gems "foo 2.0", :source => "git@#{lib_path("foo")}"
end
diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb
index 0d340b070e..d3591cd62a 100644
--- a/spec/bundler/lock/lockfile_spec.rb
+++ b/spec/bundler/lock/lockfile_spec.rb
@@ -1134,7 +1134,7 @@ RSpec.describe "the lockfile format" do
G
expect(bundled_app_lock).not_to exist
- expect(err).to include "rack (>= 0) should come from an unspecified source and git://hubz.com (at master)"
+ expect(err).to include "rack (>= 0) should come from an unspecified source and git://hubz.com"
end
it "works correctly with multiple version dependencies" do
diff --git a/spec/bundler/realworld/edgecases_spec.rb b/spec/bundler/realworld/edgecases_spec.rb
index 0f19cc7842..eb38613742 100644
--- a/spec/bundler/realworld/edgecases_spec.rb
+++ b/spec/bundler/realworld/edgecases_spec.rb
@@ -451,9 +451,35 @@ RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do
bundle :lock, :env => { "DEBUG_RESOLVER" => "1" }
if Bundler.feature_flag.bundler_3_mode?
- expect(out).to include("BUNDLER: Finished resolution (2492 steps)")
+ expect(out).to include("BUNDLER: Finished resolution (1336 steps)")
else
- expect(out).to include("BUNDLER: Finished resolution (2722 steps)")
+ expect(out).to include("BUNDLER: Finished resolution (1395 steps)")
+ end
+ end
+
+ it "doesn't hang on tricky gemfile" do
+ skip "Only for ruby 2.7.2" if RUBY_VERSION != "2.7.2"
+
+ gemfile <<~G
+ source 'https://rubygems.org'
+
+ group :development do
+ gem "puppet-module-posix-default-r2.7", '~> 0.3'
+ gem "puppet-module-posix-dev-r2.7", '~> 0.3'
+ gem "beaker-rspec"
+ gem "beaker-puppet"
+ gem "beaker-docker"
+ gem "beaker-puppet_install_helper"
+ gem "beaker-module_install_helper"
+ end
+ G
+
+ bundle :lock, :env => { "DEBUG_RESOLVER" => "1" }
+
+ if Bundler.feature_flag.bundler_3_mode?
+ expect(out).to include("BUNDLER: Finished resolution (366 steps)")
+ else
+ expect(out).to include("BUNDLER: Finished resolution (372 steps)")
end
end
end
diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb
index ead826c4e6..7b15a9b644 100644
--- a/spec/bundler/runtime/setup_spec.rb
+++ b/spec/bundler/runtime/setup_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe "Bundler.setup" do
G
ruby <<-RUBY
- require '#{lib_dir}/bundler'
+ require 'bundler'
Bundler.setup
require 'rack'
@@ -34,7 +34,7 @@ RSpec.describe "Bundler.setup" do
it "doesn't make all groups available" do
ruby <<-RUBY
- require '#{lib_dir}/bundler'
+ require 'bundler'
Bundler.setup(:default)
begin
@@ -49,7 +49,7 @@ RSpec.describe "Bundler.setup" do
it "accepts string for group name" do
ruby <<-RUBY
- require '#{lib_dir}/bundler'
+ require 'bundler'
Bundler.setup(:default, 'test')
require 'rack'
@@ -61,7 +61,7 @@ RSpec.describe "Bundler.setup" do
it "leaves all groups available if they were already" do
ruby <<-RUBY
- require '#{lib_dir}/bundler'
+ require 'bundler'
Bundler.setup
Bundler.setup(:default)
@@ -74,7 +74,7 @@ RSpec.describe "Bundler.setup" do
it "leaves :default available if setup is called twice" do
ruby <<-RUBY
- require '#{lib_dir}/bundler'
+ require 'bundler'
Bundler.setup(:default)
Bundler.setup(:default, :test)
@@ -91,7 +91,7 @@ RSpec.describe "Bundler.setup" do
it "handles multiple non-additive invocations" do
ruby <<-RUBY, :raise_on_error => false
- require '#{lib_dir}/bundler'
+ require 'bundler'
Bundler.setup(:default, :test)
Bundler.setup(:default)
require 'rack'
@@ -122,7 +122,7 @@ RSpec.describe "Bundler.setup" do
ENV["RUBYLIB"] = "rubylib_dir"
ruby <<-RUBY
- require '#{lib_dir}/bundler'
+ require 'bundler'
Bundler.setup
puts $LOAD_PATH
RUBY
@@ -143,6 +143,10 @@ RSpec.describe "Bundler.setup" do
gem "rails"
G
+ # We require an absolute path because relying on the $LOAD_PATH behaves
+ # inconsistently depending on whether we're in a ruby-core setup (and
+ # bundler's lib is in RUBYLIB) or not.
+
ruby <<-RUBY
require '#{lib_dir}/bundler'
Bundler.setup
@@ -171,6 +175,10 @@ RSpec.describe "Bundler.setup" do
gem "terranova"
G
+ # We require an absolute path because relying on the $LOAD_PATH behaves
+ # inconsistently depending on whether we're in a ruby-core setup (and
+ # bundler's lib is in RUBYLIB) or not.
+
ruby <<-RUBY
require '#{lib_dir}/bundler/setup'
puts $LOAD_PATH
@@ -192,8 +200,10 @@ RSpec.describe "Bundler.setup" do
gem "rack"
G
+ entrypoint = mis_activates_prerelease_default_bundler? ? "#{lib_dir}/bundler" : "bundler"
+
ruby <<-R
- require '#{lib_dir}/bundler'
+ require '#{entrypoint}'
begin
Bundler.setup
@@ -213,7 +223,7 @@ RSpec.describe "Bundler.setup" do
G
ruby <<-R, :raise_on_error => false
- require '#{lib_dir}/bundler'
+ require 'bundler'
Bundler.setup
R
@@ -236,7 +246,7 @@ RSpec.describe "Bundler.setup" do
G
ruby <<-R, :raise_on_error => false
- require '#{lib_dir}/bundler'
+ require 'bundler'
Bundler.setup
R
@@ -289,7 +299,7 @@ RSpec.describe "Bundler.setup" do
ENV["BUNDLE_GEMFILE"] = "Gemfile"
ruby <<-R
- require '#{lib_dir}/bundler'
+ require 'bundler'
begin
Bundler.setup
@@ -444,7 +454,7 @@ RSpec.describe "Bundler.setup" do
break_git!
ruby <<-R
- require '#{lib_dir}/bundler'
+ require 'bundler'
begin
Bundler.setup
@@ -464,8 +474,10 @@ RSpec.describe "Bundler.setup" do
break_git!
+ entrypoint = mis_activates_prerelease_default_bundler? ? "#{lib_dir}/bundler" : "bundler"
+
ruby <<-R
- require "#{lib_dir}/bundler"
+ require "#{entrypoint}"
begin
Bundler.setup
@@ -798,7 +810,7 @@ end
# Don't build extensions.
s.class.send(:define_method, :build_extensions) { nil }
- require '#{lib_dir}/bundler'
+ require 'bundler'
gem '#{gem_name}'
puts $LOAD_PATH.count {|path| path =~ /#{gem_name}/} >= 2
@@ -1056,7 +1068,7 @@ end
bundle "install"
ruby <<-RUBY
- require '#{lib_dir}/bundler'
+ require 'bundler'
bundler_module = class << Bundler; self; end
bundler_module.send(:remove_method, :require)
def Bundler.require(path)
@@ -1104,6 +1116,8 @@ end
end
before do
+ bundle "config set --local path.system true"
+
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "rack"
@@ -1112,8 +1126,9 @@ end
context "is not present" do
it "does not change the lock" do
+ entrypoint = mis_activates_prerelease_default_bundler? ? "#{lib_dir}/bundler/setup" : "bundler/setup"
lockfile lock_with(nil)
- ruby "require '#{lib_dir}/bundler/setup'"
+ ruby "require '#{entrypoint}'"
lockfile_should_be lock_with(nil)
end
end
@@ -1121,7 +1136,7 @@ end
context "is newer" do
it "does not change the lock or warn" do
lockfile lock_with(Bundler::VERSION.succ)
- ruby "require '#{lib_dir}/bundler/setup'"
+ ruby "require 'bundler/setup'"
expect(out).to be_empty
expect(err).to be_empty
lockfile_should_be lock_with(Bundler::VERSION.succ)
@@ -1130,8 +1145,10 @@ end
context "is older" do
it "does not change the lock" do
+ entrypoint = mis_activates_prerelease_default_bundler? ? "#{lib_dir}/bundler/setup" : "bundler/setup"
+ system_gems "bundler-1.10.1"
lockfile lock_with("1.10.1")
- ruby "require '#{lib_dir}/bundler/setup'"
+ ruby "require '#{entrypoint}'"
lockfile_should_be lock_with("1.10.1")
end
end
@@ -1178,14 +1195,14 @@ end
context "is not present" do
it "does not change the lock" do
- expect { ruby "require '#{lib_dir}/bundler/setup'" }.not_to change { lockfile }
+ expect { ruby "require 'bundler/setup'" }.not_to change { lockfile }
end
end
context "is newer" do
let(:ruby_version) { "5.5.5" }
it "does not change the lock or warn" do
- expect { ruby "require '#{lib_dir}/bundler/setup'" }.not_to change { lockfile }
+ expect { ruby "require 'bundler/setup'" }.not_to change { lockfile }
expect(out).to be_empty
expect(err).to be_empty
end
@@ -1194,7 +1211,7 @@ end
context "is older" do
let(:ruby_version) { "1.0.0" }
it "does not change the lock" do
- expect { ruby "require '#{lib_dir}/bundler/setup'" }.not_to change { lockfile }
+ expect { ruby "require 'bundler/setup'" }.not_to change { lockfile }
end
end
end
@@ -1202,8 +1219,9 @@ end
describe "with gemified standard libraries" do
it "does not load Psych" do
gemfile ""
+ entrypoint = mis_activates_prerelease_default_bundler? ? "#{lib_dir}/bundler/setup" : "bundler/setup"
ruby <<-RUBY
- require '#{lib_dir}/bundler/setup'
+ require '#{entrypoint}'
puts defined?(Psych::VERSION) ? Psych::VERSION : "undefined"
require 'psych'
puts Psych::VERSION
@@ -1216,7 +1234,7 @@ end
it "does not load openssl" do
install_gemfile ""
ruby <<-RUBY
- require "#{lib_dir}/bundler/setup"
+ require "bundler/setup"
puts defined?(OpenSSL) || "undefined"
require "openssl"
puts defined?(OpenSSL) || "undefined"
@@ -1274,7 +1292,7 @@ end
it "activates no gems with -rbundler/setup" do
install_gemfile ""
- ruby code, :env => { "RUBYOPT" => activation_warning_hack_rubyopt + " -r#{lib_dir}/bundler/setup" }
+ ruby code, :env => { "RUBYOPT" => activation_warning_hack_rubyopt + " -rbundler/setup" }
expect(out).to eq("{}")
end
@@ -1327,7 +1345,7 @@ end
if File.exist?(ext_folder.join("#{require_name}.rb"))
{ :exclude_from_load_path => ext_folder.to_s }
else
- lib_folder = source_root.join("lib")
+ lib_folder = source_lib_dir
if File.exist?(lib_folder.join("#{require_name}.rb"))
{ :exclude_from_load_path => lib_folder.to_s }
else
@@ -1383,7 +1401,7 @@ end
G
ruby <<-RUBY
- require "#{lib_dir}/bundler/setup"
+ require "bundler/setup"
Object.new.gem "rack"
puts Gem.loaded_specs["rack"].full_name
RUBY
@@ -1398,7 +1416,7 @@ end
G
ruby <<-RUBY, :raise_on_error => false
- require "#{lib_dir}/bundler/setup"
+ require "bundler/setup"
Object.new.gem "rack"
puts "FAIL"
RUBY
@@ -1414,7 +1432,7 @@ end
G
ruby <<-RUBY, :raise_on_error => false
- require "#{lib_dir}/bundler/setup"
+ require "bundler/setup"
Object.new.require "rack"
puts "FAIL"
RUBY
@@ -1429,4 +1447,9 @@ end
expect(last_command.stdboth).to eq("true")
end
end
+
+ # Tested rubygems does not include https://github.com/rubygems/rubygems/pull/2728 and will not always end up activating the current bundler
+ def mis_activates_prerelease_default_bundler?
+ Gem.rubygems_version < Gem::Version.new("3.1.a")
+ end
end
diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb
index 02a2c0f659..c76c3f505e 100644
--- a/spec/bundler/support/builders.rb
+++ b/spec/bundler/support/builders.rb
@@ -547,9 +547,11 @@ module Spec
class GitBuilder < LibBuilder
def _build(options)
+ default_branch = options[:default_branch] || "master"
path = options[:path] || _default_path
source = options[:source] || "git@#{path}"
super(options.merge(:path => path, :source => source))
+ @context.git("config --global init.defaultBranch #{default_branch}", path)
@context.git("init", path)
@context.git("add *", path)
@context.git("config user.email lol@wut.com", path)