[rubygems/rubygems] Restore previous application cache format for git sources

And make sure `bundle install --local` can install from it without git.

https://github.com/rubygems/rubygems/commit/7d6b631620
This commit is contained in:
David Rodríguez 2024-11-22 11:14:08 +01:00 committed by git
parent 2a8437a1eb
commit 9a4d91fa95
4 changed files with 18 additions and 22 deletions

View File

@ -139,6 +139,11 @@ module Bundler
spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache)
end
Dir[cache_path.join("*/.git")].each do |git_dir|
FileUtils.rm_rf(git_dir)
FileUtils.touch(File.expand_path("../.bundlecache", git_dir))
end
prune_cache(cache_path) unless Bundler.settings[:no_prune]
end

View File

@ -188,12 +188,10 @@ module Bundler
end
def specs(*)
set_up_app_cache!(app_cache_path) if use_app_cache?
set_cache_path!(app_cache_path) if use_app_cache?
if requires_checkout? && !@copied
FileUtils.rm_rf(app_cache_path) if use_app_cache? && git_proxy.not_a_repository?
fetch
fetch unless use_app_cache?
checkout
end
@ -225,9 +223,7 @@ module Bundler
cached!
FileUtils.rm_rf(app_cache_path)
git_proxy.checkout if requires_checkout?
FileUtils.cp_r("#{cache_path}/.", app_cache_path)
FileUtils.touch(app_cache_path.join(".bundlecache"))
FileUtils.rm_rf(Dir.glob(app_cache_path.join("hooks/*.sample")))
git_proxy.copy_to(app_cache_path, @submodules)
end
def load_spec_files
@ -273,7 +269,14 @@ module Bundler
def checkout
Bundler.ui.debug " * Checking out revision: #{ref}"
git_proxy.copy_to(install_path, submodules)
if use_app_cache?
SharedHelpers.filesystem_access(install_path.dirname) do |p|
FileUtils.mkdir_p(p)
end
FileUtils.cp_r("#{app_cache_path}/.", install_path)
else
git_proxy.copy_to(install_path, submodules)
end
serialize_gemspecs_in(install_path)
@copied = true
end
@ -321,11 +324,6 @@ module Bundler
@install_path = path
end
def set_up_app_cache!(path)
FileUtils.mkdir_p(path.join("refs"))
set_cache_path!(path)
end
def has_app_cache?
locked_revision && super
end

View File

@ -84,12 +84,6 @@ module Bundler
end
end
def not_a_repository?
_, status = git_null("rev-parse", "--resolve-git-dir", path.to_s, dir: path)
!status.success?
end
def contains?(commit)
allowed_with_path do
result, status = git_null("branch", "--contains", commit, dir: path)

View File

@ -27,7 +27,6 @@ RSpec.describe "bundle cache with git" do
expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist
expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist
expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.bundlecache")).to be_file
expect(Dir.glob(bundled_app("vendor/cache/foo-1.0-#{ref}/hooks/*.sample"))).to be_empty
FileUtils.rm_rf lib_path("foo-1.0")
expect(the_bundle).to include_gems "foo 1.0"
@ -240,7 +239,7 @@ RSpec.describe "bundle cache with git" do
expect(the_bundle).to include_gem "foo 1.0"
end
it "copies repository to vendor cache" do
it "copies repository to vendor cache, including submodules" do
# CVE-2022-39253: https://lore.kernel.org/lkml/xmqq4jw1uku5.fsf@gitster.g/
system(*%W[git config --global protocol.file.allow always])
@ -265,6 +264,7 @@ RSpec.describe "bundle cache with git" do
bundle :cache
expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist
expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0")).to exist
expect(the_bundle).to include_gems "has_submodule 1.0"
end
@ -275,7 +275,6 @@ RSpec.describe "bundle cache with git" do
source "https://gem.repo1"
gem "foo", :git => '#{lib_path("foo-1.0")}'
G
bundle "config set path vendor/bundle"
bundle "config set cache_all true"
bundle :cache, "all-platforms" => true, :install => false